init
This commit is contained in:
56
local/utl/common/common.go
Normal file
56
local/utl/common/common.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type RouteGroups struct {
|
||||
Api fiber.Router
|
||||
}
|
||||
|
||||
func CheckError(err error) {
|
||||
if err != nil {
|
||||
log.Printf("Error occured. %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
|
||||
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
|
||||
|
||||
func ToSnakeCase(str string) string {
|
||||
snake := matchFirstCap.ReplaceAllString(str, "${1}_${2}")
|
||||
snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}")
|
||||
return strings.ToLower(snake)
|
||||
}
|
||||
|
||||
func GetIP() string {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
os.Stderr.WriteString("Oops: " + err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, a := range addrs {
|
||||
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Find[T any](lst *[]T, callback func(item *T) bool) *T {
|
||||
for _, item := range *lst {
|
||||
if callback(&item) {
|
||||
return &item
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
8
local/utl/configs/configs.go
Normal file
8
local/utl/configs/configs.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package configs
|
||||
|
||||
const (
|
||||
Version = "0.0.1"
|
||||
Prefix = "v1"
|
||||
Secret = "Donde4sta"
|
||||
SecretCode = "brasno"
|
||||
)
|
||||
25
local/utl/server/server.go
Normal file
25
local/utl/server/server.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/utl/common"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Start(r *fiber.App) *fiber.App {
|
||||
r.Get("/ping", func(c *fiber.Ctx) error {
|
||||
return c.SendString("pong")
|
||||
})
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "4000"
|
||||
}
|
||||
err := r.Listen(":" + port)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Running on %s:%s", common.GetIP(), port)
|
||||
println(msg)
|
||||
}
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user