You've already forked directdnsonly-go
Initial Project
This commit is contained in:
58
cmd/directdnsonly/main.go
Normal file
58
cmd/directdnsonly/main.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/guisea/directdnsonly/internal/handlers"
|
||||
"github.com/guisea/directdnsonly/internal/version"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
echoLog "github.com/labstack/gommon/log"
|
||||
EchoLogrusMiddleware "github.com/neko-neko/echo-logrus/v2"
|
||||
"github.com/neko-neko/echo-logrus/v2/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
e.HidePort = true
|
||||
e.Debug = true
|
||||
|
||||
// Logger Handler
|
||||
log.Logger().SetOutput(os.Stdout)
|
||||
log.Logger().SetLevel(echoLog.INFO)
|
||||
log.Logger().SetFormatter(&logrus.JSONFormatter{
|
||||
TimestampFormat: time.RFC3339,
|
||||
})
|
||||
e.Logger = log.Logger()
|
||||
|
||||
e.Use(middleware.Recover(),
|
||||
EchoLogrusMiddleware.Logger(),
|
||||
middleware.RequestID(),
|
||||
middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
|
||||
// Be careful to use constant time comparison to prevent timing attacks
|
||||
if subtle.ConstantTimeCompare([]byte(username), []byte("test")) == 1 &&
|
||||
subtle.ConstantTimeCompare([]byte(password), []byte("test")) == 1 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}))
|
||||
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Hello, World!")
|
||||
})
|
||||
|
||||
e.GET("/CMD_API_LOGIN_TEST", handlers.LoginTest)
|
||||
e.Match([]string{"GET", "POST"}, "/CMD_API_DNS_ADMIN", handlers.DNSAdmin)
|
||||
log.Info("Directdnsonly Version: " + version.Version + " Started!!")
|
||||
log.Info("Build Date: ", version.BuildDate)
|
||||
log.Info("Go Version: ", version.GoVersion)
|
||||
log.Info("OS / Arch: ", version.OsArch)
|
||||
e.Logger.Fatal(e.Start(":1323"))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user