Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var SetupServer = func(appPort string) { var router = httprouter.New() router.GET("/ping", TokenAuthentication(controllers.Ping)) router.GET("/env", TokenAuthentication(controllers.GetEnvVars)) router.POST("/env", TokenAuthentication(controllers.SetEnvVars)) router.GET("/env/:name", TokenAuthentication(controllers.GetEnvVar)) router.GET("/about", TokenAuthentication(controllers.About)) router.GET("/file", TokenAuthentication(controllers.GetFile)) router.PUT("/file", TokenAuthentication(controllers.PutFile)) router.GET("/folder", TokenAuthentication(controllers.GetFolder)) router.POST("/command", TokenAuthentication(controllers.CommandPost)) router.POST("/commandparallel", TokenAuthentication(controllers.CommandParallelPost)) router.POST("/commanddetached/:cid", TokenAuthentication(controllers.CommandDetachedPost)) err := http.ListenAndServe(":"+appPort, router) if err != nil { fmt.Print(err) } }
View Source
var TokenAuthentication = func(h httprouter.Handle) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { tokenHeader := r.Header.Get("Token") if tokenHeader == os.Getenv("HTTP_AUTH_TOKEN") { h(w, r, ps) } else { response, _ := json.Marshal(u.ApiMessage(uint32(constants.UNAUTHORIZED), u.GetMessage()[uint32(constants.UNAUTHORIZED)], "Invalid Token", r.URL.Path)) w.Header().Add("Content-Type", "application/json") http.Error(w, string(response), http.StatusUnauthorized) } } }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.