🎨 add helper functions and general cleanup

This commit is contained in:
2024-01-24 11:04:43 +01:00
parent 57722116d6
commit 71ea9cac18
7 changed files with 53 additions and 42 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}