🎨 add helper functions and general cleanup
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
@ -59,3 +60,11 @@ func (br *BaseRule) baseUpdate(rule HostnameRule, category string, oldhostname s
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// @Summary Generate hostname for category "notebook"
|
||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||
// @ID insert-notebook-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Generating Hostnames
|
||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/notebook [post]
|
||||
// @Security Bearer
|
||||
// @Summary Generate hostname for category "notebook"
|
||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||
// @ID insert-notebook-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Generating Hostnames
|
||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/notebook [post]
|
||||
// @Security Bearer
|
||||
func (nr *NotebookRule) Insert(category string, params map[string]interface{}) (string, error) {
|
||||
// Generate the hostname
|
||||
|
||||
return nr.baseInsert(nr, category, params)
|
||||
}
|
||||
|
||||
// @Summary Update hostname for category "notebook"
|
||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||
// @ID update-notebook-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Manipulate existing Hostnames
|
||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/notebook [put]
|
||||
// @Security Bearer
|
||||
// @Summary Update hostname for category "notebook"
|
||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||
// @ID update-notebook-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Manipulate existing Hostnames
|
||||
// @Param body body NotebookRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/notebook [put]
|
||||
// @Security Bearer
|
||||
func (nr *NotebookRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
||||
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"
|
||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||
// @ID insert-server-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Generating Hostnames
|
||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/server [post]
|
||||
// @Security Bearer
|
||||
// @Summary Generate hostname for category "notebook"
|
||||
// @Description Generates a hostname for a notebook based on dynamic rules.
|
||||
// @ID insert-server-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Generating Hostnames
|
||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/server [post]
|
||||
// @Security Bearer
|
||||
func (nr *ServerRule) Insert(category string, params map[string]interface{}) (string, error) {
|
||||
// Generate the hostname
|
||||
|
||||
return nr.baseInsert(nr, category, params)
|
||||
}
|
||||
|
||||
// @Summary Update hostname for category "notebook"
|
||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||
// @ID update-server-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Manipulate existing Hostnames
|
||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/server [put]
|
||||
// @Security Bearer
|
||||
// @Summary Update hostname for category "notebook"
|
||||
// @Description Generates a new hostname for a notebook based on dynamic rules.
|
||||
// @ID update-server-hostname
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags Manipulate existing Hostnames
|
||||
// @Param body body ServerRuleInput true "Input data to generate hostname"
|
||||
// @Success 200 {object} models.SimpleHostnameResponse "Hostname"
|
||||
// @Router /api/server [put]
|
||||
// @Security Bearer
|
||||
func (nr *ServerRule) Update(category string, oldhostname string, params map[string]interface{}) (string, error) {
|
||||
return nr.baseUpdate(nr, category, oldhostname, params)
|
||||
}
|
||||
|
Reference in New Issue
Block a user