a quest
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.5 KiB

5 years ago
package main
import (
"flag"
"fmt"
"net"
"os"
jwtgo "github.com/dgrijalva/jwt-go"
log "github.com/sirupsen/logrus"
"github.com/valyala/fasthttp"
"github.com/mainnika/a-quest/keys"
5 years ago
"github.com/mainnika/a-quest/task1-backend/lib"
. "github.com/mainnika/a-quest/task1-backend/lib/configure"
. "github.com/mainnika/a-quest/task1-backend/lib/env"
)
var version = "dev"
var (
getVersion bool
)
func init() {
if IsDevelopment {
log.SetLevel(log.DebugLevel)
log.Debug("debug mode")
}
}
func httpStart(apiserv *lib.Api) (httpserv *fasthttp.Server) {
httpserv = &fasthttp.Server{
Logger: log.StandardLogger(),
Handler: apiserv.GetHandler(),
DisableKeepalive: true,
}
lis, err := net.Listen("tcp", Config.HttpAPI.Addr)
if err != nil {
log.Fatalf("http listen error: %v", err)
}
err = httpserv.Serve(lis)
if err != nil {
log.Fatalf("http serve error: %v", err)
}
return
}
func main() {
flag.BoolVar(&getVersion, "v", false, "version")
flag.Parse()
if getVersion {
fmt.Println(version)
os.Exit(0)
}
log.Debugf("version: %s", version)
log.Debugf("cfg: %v", Config)
pubKey, err := jwtgo.ParseECPublicKeyFromPEM(keys.PublicKey)
5 years ago
if err != nil {
log.Fatalf("can not parse jwt key: %s", err)
}
privKey, err := jwtgo.ParseECPrivateKeyFromPEM(keys.PrivateKey)
5 years ago
if err != nil {
log.Fatalf("can not parse jwt key: %s", err)
}
apiserv := &lib.Api{
Base: Config.HttpAPI.Base,
Pub: pubKey,
Priv: privKey,
Alg: keys.Alg,
Answer: keys.Answer,
5 years ago
}
httpStart(apiserv)
}