mirror of
https://github.com/h44z/wg-portal.git
synced 2025-04-19 08:55:12 +00:00
Initial alpha codebase for version 2 of WireGuard Portal. This version is considered unstable and incomplete (for example, no public REST API)! Use with care! Fixes/Implements the following issues: - OAuth support #154, #1 - New Web UI with internationalisation support #98, #107, #89, #62 - Postgres Support #49 - Improved Email handling #47, #119 - DNS Search Domain support #46 - Bugfixes #94, #48 --------- Co-authored-by: Fabian Wechselberger <wechselbergerf@hotmail.com>
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/h44z/wg-portal/internal/app/api/v0/model"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type testEndpoint struct{}
|
|
|
|
func (e testEndpoint) GetName() string {
|
|
return "TestEndpoint"
|
|
}
|
|
|
|
func (e testEndpoint) RegisterRoutes(g *gin.RouterGroup, authenticator *authenticationHandler) {
|
|
g.GET("/now", e.handleCurrentTimeGet())
|
|
g.GET("/hostname", e.handleHostnameGet())
|
|
}
|
|
|
|
// handleCurrentTimeGet represents the GET endpoint that responds the current time
|
|
//
|
|
// @ID test_handleCurrentTimeGet
|
|
// @Tags Testing
|
|
// @Summary Get the current local time.
|
|
// @Description Nothing more to describe...
|
|
// @Produce json
|
|
// @Success 200 {object} string
|
|
// @Failure 500 {object} model.Error
|
|
// @Router /now [get]
|
|
func (e testEndpoint) handleCurrentTimeGet() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if time.Now().Second() == 0 {
|
|
c.JSON(http.StatusInternalServerError, model.Error{
|
|
Code: http.StatusInternalServerError,
|
|
Message: "invalid time",
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, time.Now().String())
|
|
}
|
|
}
|
|
|
|
// handleHostnameGet represents the GET endpoint that responds the current hostname
|
|
//
|
|
// @ID test_handleHostnameGet
|
|
// @Tags Testing
|
|
// @Summary Get the current host name.
|
|
// @Description Nothing more to describe...
|
|
// @Produce json
|
|
// @Success 200 {object} string
|
|
// @Failure 500 {object} model.Error
|
|
// @Router /hostname [get]
|
|
func (e testEndpoint) handleHostnameGet() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Error{
|
|
Code: http.StatusInternalServerError,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, hostname)
|
|
}
|
|
}
|