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.
85 lines
1.8 KiB
85 lines
1.8 KiB
3 years ago
|
package main
|
||
|
|
||
|
import (
|
||
3 years ago
|
"fmt"
|
||
3 years ago
|
"net"
|
||
3 years ago
|
"time"
|
||
3 years ago
|
|
||
3 years ago
|
"github.com/sirupsen/logrus"
|
||
|
"github.com/spf13/viper"
|
||
3 years ago
|
"github.com/valyala/fasthttp"
|
||
3 years ago
|
|
||
3 years ago
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/v4api/httpclient"
|
||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/routes"
|
||
|
_ "code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
var Version = "nightly"
|
||
|
|
||
3 years ago
|
const frontendServerIdentity = "Microsoft-IIS/6.0"
|
||
|
|
||
3 years ago
|
func main() {
|
||
|
|
||
3 years ago
|
if viper.GetBool("version") {
|
||
|
fmt.Print(Version)
|
||
|
return
|
||
|
}
|
||
|
|
||
3 years ago
|
viper.SetConfigFile(viper.GetString("config"))
|
||
|
if err := viper.ReadInConfig(); err != nil {
|
||
|
logrus.Debugf("Skip invalid config file %s, %v", viper.ConfigFileUsed(), err)
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
config := &config.Config{}
|
||
|
if err := viper.Unmarshal(config); err != nil {
|
||
|
logrus.Warnf("Cannot unmarshal config, %v", err)
|
||
|
}
|
||
|
|
||
3 years ago
|
var netw, addr string
|
||
|
switch {
|
||
|
case config.Addr != "":
|
||
|
netw = "tcp"
|
||
|
addr = config.Addr
|
||
|
case config.Unix != "":
|
||
|
netw = "unix"
|
||
|
addr = config.Unix
|
||
|
default:
|
||
|
panic("no address given")
|
||
|
}
|
||
|
netListener, err := net.Listen(netw, addr)
|
||
|
if err != nil {
|
||
|
logrus.Fatal(err)
|
||
|
}
|
||
|
|
||
3 years ago
|
ghostClient := &httpclient.HTTPClient{
|
||
3 years ago
|
Addr: config.Content.Backend.Addr,
|
||
|
Secured: config.Content.Backend.Secured,
|
||
3 years ago
|
Headers: config.Content.Backend.Headers,
|
||
3 years ago
|
ContentKey: config.Content.Key,
|
||
|
QueryTimeout: time.Second,
|
||
|
}
|
||
|
|
||
3 years ago
|
apiRoutes := &routes.Routes{
|
||
3 years ago
|
GhostClient: ghostClient,
|
||
3 years ago
|
ContentConfig: config.Content,
|
||
3 years ago
|
Base: config.Base,
|
||
|
}
|
||
|
|
||
3 years ago
|
httpServer := fasthttp.Server{
|
||
|
Logger: logrus.StandardLogger(),
|
||
3 years ago
|
Handler: apiRoutes.Handler,
|
||
3 years ago
|
Name: frontendServerIdentity,
|
||
3 years ago
|
GetOnly: true,
|
||
|
}
|
||
|
|
||
3 years ago
|
logrus.Infof("Version: %s", Version)
|
||
3 years ago
|
logrus.Debugf("Addr: %s+%s", netw, addr)
|
||
3 years ago
|
logrus.Debugf("Conf: %#v", config)
|
||
3 years ago
|
|
||
|
err = httpServer.Serve(netListener)
|
||
|
if err != nil {
|
||
|
logrus.Fatal(err)
|
||
|
}
|
||
3 years ago
|
}
|