From 74f160114b5e931facc4c38d9c73d65fff9a8147 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Mon, 28 Nov 2016 13:09:10 +0200 Subject: [PATCH] Moved HTTP server methods to main --- main.go | 32 ++++++++++++++++++++++++++++++++ util.go | 32 -------------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index ce895f8..8d017b9 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,8 @@ package main import ( log "github.com/Sirupsen/logrus" + "github.com/iris-contrib/middleware/cors" + "github.com/kataras/iris" "os" ) @@ -42,3 +44,33 @@ func main() { log.Debugf("Shutting down...") } + +func startHTTPAPI() { + api := iris.New() + api.Config.DisableBanner = true + crs := cors.New(cors.Options{ + AllowedOrigins: DNSConf.API.CorsOrigins, + AllowedMethods: []string{"GET", "POST"}, + OptionsPassthrough: false, + Debug: DNSConf.General.Debug, + }) + api.Use(crs) + var ForceAuth = authMiddleware{} + api.Get("/register", webRegisterGet) + api.Post("/register", webRegisterPost) + api.Post("/update", ForceAuth.Serve, webUpdatePost) + switch DNSConf.API.TLS { + case "letsencrypt": + listener, err := iris.LETSENCRYPTPROD(DNSConf.API.Domain) + err = api.Serve(listener) + if err != nil { + log.Errorf("Error in HTTP server [%v]", err) + } + case "cert": + host := DNSConf.API.Domain + ":" + DNSConf.API.Port + api.ListenTLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey) + default: + host := DNSConf.API.Domain + ":" + DNSConf.API.Port + api.Listen(host) + } +} diff --git a/util.go b/util.go index 4898d7d..74d8964 100644 --- a/util.go +++ b/util.go @@ -5,8 +5,6 @@ import ( "fmt" "github.com/BurntSushi/toml" log "github.com/Sirupsen/logrus" - "github.com/iris-contrib/middleware/cors" - "github.com/kataras/iris" "github.com/miekg/dns" "github.com/satori/go.uuid" "math/big" @@ -89,33 +87,3 @@ func startDNS(listen string) *dns.Server { }() return server } - -func startHTTPAPI() { - api := iris.New() - api.Config.DisableBanner = true - crs := cors.New(cors.Options{ - AllowedOrigins: DNSConf.API.CorsOrigins, - AllowedMethods: []string{"GET", "POST"}, - OptionsPassthrough: false, - Debug: DNSConf.General.Debug, - }) - api.Use(crs) - var ForceAuth = authMiddleware{} - api.Get("/register", webRegisterGet) - api.Post("/register", webRegisterPost) - api.Post("/update", ForceAuth.Serve, webUpdatePost) - switch DNSConf.API.TLS { - case "letsencrypt": - listener, err := iris.LETSENCRYPTPROD(DNSConf.API.Domain) - err = api.Serve(listener) - if err != nil { - log.Errorf("Error in HTTP server [%v]", err) - } - case "cert": - host := DNSConf.API.Domain + ":" + DNSConf.API.Port - api.ListenTLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey) - default: - host := DNSConf.API.Domain + ":" + DNSConf.API.Port - api.Listen(host) - } -}