🎨 add helper functions and general cleanup
This commit is contained in:
parent
57722116d6
commit
71ea9cac18
|
@ -1,4 +1,4 @@
|
||||||
CREATE TABLE hostnames (
|
CREATE TABLE IF NOT EXISTS hostnames (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
category TEXT NOT NULL,
|
category TEXT NOT NULL,
|
||||||
hostname TEXT NOT NULL,
|
hostname TEXT NOT NULL,
|
1
go.mod
1
go.mod
|
@ -27,6 +27,7 @@ require (
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
|
github.com/gin-contrib/cors v1.5.0
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -22,6 +22,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||||
|
github.com/gin-contrib/cors v1.5.0 h1:DgGKV7DDoOn36DFkNtbHrjoRiT5ExCe+PC9/xp7aKvk=
|
||||||
|
github.com/gin-contrib/cors v1.5.0/go.mod h1:TvU7MAZ3EwrPLI2ztzTt3tqgvBCq+wn8WpZmfADjupI=
|
||||||
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
||||||
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
|
|
|
@ -44,7 +44,6 @@ func New() *gin.Engine {
|
||||||
{
|
{
|
||||||
// public routes
|
// public routes
|
||||||
v1.POST("/login", auth.LoginHandler)
|
v1.POST("/login", auth.LoginHandler)
|
||||||
v1.GET("/login", api.Helloworld)
|
|
||||||
|
|
||||||
// Protected Routes
|
// Protected Routes
|
||||||
authenticated := v1.Group("/").Use(middleware.Authenticate())
|
authenticated := v1.Group("/").Use(middleware.Authenticate())
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rules
|
package rules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -59,3 +60,11 @@ func (br *BaseRule) baseUpdate(rule HostnameRule, category string, oldhostname s
|
||||||
|
|
||||||
return newHostname, nil
|
return newHostname, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StructToJSON(v interface{}) (string, error) {
|
||||||
|
bytes, err := json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(bytes), nil
|
||||||
|
}
|
||||||
|
|
|
@ -66,32 +66,32 @@ func (nr *NotebookRule) Generate(params map[string]interface{}) (string, []byte,
|
||||||
return hostname, paramsJSON, nil
|
return hostname, paramsJSON, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Generate hostname for category "notebook"
|
// @Summary Generate hostname for category "notebook"
|
||||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||||
// @ID insert-notebook-hostname
|
// @ID insert-notebook-hostname
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags Generating Hostnames
|
// @Tags Generating Hostnames
|
||||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||||
// @Router /api/notebook [post]
|
// @Router /api/notebook [post]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (nr *NotebookRule) Insert(category string, params map[string]interface{}) (string, error) {
|
func (nr *NotebookRule) Insert(category string, params map[string]interface{}) (string, error) {
|
||||||
// Generate the hostname
|
// Generate the hostname
|
||||||
|
|
||||||
return nr.baseInsert(nr, category, params)
|
return nr.baseInsert(nr, category, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update hostname for category "notebook"
|
// @Summary Update hostname for category "notebook"
|
||||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||||
// @ID update-notebook-hostname
|
// @ID update-notebook-hostname
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags Manipulate existing Hostnames
|
// @Tags Manipulate existing Hostnames
|
||||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||||
// @Router /api/notebook [put]
|
// @Router /api/notebook [put]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (nr *NotebookRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
func (nr *NotebookRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
||||||
return nr.baseUpdate(nr, category, oldhostname, params)
|
return nr.baseUpdate(nr, category, oldhostname, params)
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,32 +108,32 @@ func (sr *ServerRule) Generate(params map[string]interface{}) (string, []byte, e
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Generate hostname for category "notebook"
|
// @Summary Generate hostname for category "notebook"
|
||||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||||
// @ID insert-server-hostname
|
// @ID insert-server-hostname
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags Generating Hostnames
|
// @Tags Generating Hostnames
|
||||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||||
// @Router /api/server [post]
|
// @Router /api/server [post]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (nr *ServerRule) Insert(category string, params map[string]interface{}) (string, error) {
|
func (nr *ServerRule) Insert(category string, params map[string]interface{}) (string, error) {
|
||||||
// Generate the hostname
|
// Generate the hostname
|
||||||
|
|
||||||
return nr.baseInsert(nr, category, params)
|
return nr.baseInsert(nr, category, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update hostname for category "notebook"
|
// @Summary Update hostname for category "notebook"
|
||||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||||
// @ID update-server-hostname
|
// @ID update-server-hostname
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags Manipulate existing Hostnames
|
// @Tags Manipulate existing Hostnames
|
||||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||||
// @Router /api/server [put]
|
// @Router /api/server [put]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func (nr *ServerRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
func (nr *ServerRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
||||||
return nr.baseUpdate(nr, category, oldhostname, params)
|
return nr.baseUpdate(nr, category, oldhostname, params)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue