func DefaultCallbackTemplateFunction(*ConfigTemplateContext) hctypes.Dict
func Schedule(host string, module_manager_url string)
Schedule for monitoring the module
Parameters:
host - the host address module_manager_url - the URL of the module manager
type Config struct {
Namespace string `json:"namespace,omitempty"`
Server ConfigServer `json:"server,omitempty"`
Templates []*ConfigTemplate `json:"templates,omitempty"`
APIs []*ConfigAPI `json:"apis,omitempty"`
Options hctypes.Dict `json:"options,omitempty"`
// contains filtered or unexported fields
}
func LoadConfig() (*Config, error)
func (config *Config) ForPublic() *Config
func (conf *Config) LoadOptionsStrapiSchemas() map[string]string
LoadOptionsStrapiSchemas loads Strapi schemas and returns a map of paths to the created schema files.
No parameters. Returns a map of strings where the key is the file path and the value is the created schema file content.
func (config *Config) LoadPlugin() error
func (config *Config) Run()
Example: ./config.json
```json
{
"namespace": "api-registration",
"server": {
"port": 8080
},
"templates": [
{
"name": "registration",
"path": "/",
"file_path": "example/template.html"
}
],
"apis": [
{
"name": "registration",
"path": "/registration",
"method": "POST",
"content_type": "application/json",
"response_type": "application/json",
"callback": {
"plugin": "plugin.so",
"function": "Registration"
},
"params": [
{
"name": "username",
"label": "Username",
"placeholder": "Enter Username",
"type": "username",
"validate": "username",
"required": true,
"min": 5,
"max": 32
},
{
"name": "fullname",
"label": "Full Name",
"placeholder": "Enter Full Name",
"type": "name",
"validate": "name",
"required": true,
"min": 5,
"max": 32
},
{
"name": "email",
"label": "Email Address",
"placeholder": "Enter Email Address",
"type": "email",
"required": true,
"min": 5,
"max": 32
},
{
"name": "password",
"label": "Password",
"placeholder": "Enter Password",
"type": "password",
"required": true,
"min": 8,
"max": 120
},
{
"name": "confirm_password",
"label": "Confirm Password",
"placeholder": "Enter Confirm Password",
"type": "password",
"required": true,
"min": 8,
"max": 120
}
]
},
{
"name": "verification",
"path": "/verification/:id/:otp",
"method": "GET",
"content_type": "application/json",
"response_type": "application/json",
"callback": {
"plugin": "plugin.so",
"function": "Verification"
},
"url_params": [
{
"name": "id",
"type": "textnumber",
"required": true
},
{
"name": "otp",
"type": "textnumber",
"required": true
}
]
}
]
}
```
Example: main.go
```go
package main
import (
"fmt"
"gitlab.hexacode.org/go-libs/hctypes"
"gitlab.hexacode.org/go-libs/microservice/config"
)
func Registration(ctx *config.ConfigContext) (int, hctypes.Dict, *config.ReturnHTTP) {
fmt.Println(ctx.Config.ToDict().ToColoredJson())
fmt.Println(ctx.ConfigApi.ToDict().ToColoredJson())
fmt.Println(ctx.URLParams.ToColoredJson())
fmt.Println(ctx.Params.ToColoredJson())
fmt.Println(ctx.Headers.ToColoredJson())
return 200, hctypes.Dict{
"id": 1,
"otp": 123456,
}, nil
}
func Verification(ctx *config.ConfigContext) (int, hctypes.Dict, *config.ReturnHTTP) {
fmt.Println(ctx.Config.ToDict().ToColoredJson())
fmt.Println(ctx.ConfigApi.ToDict().ToColoredJson())
fmt.Println(ctx.URLParams.ToColoredJson())
fmt.Println(ctx.Params.ToColoredJson())
fmt.Println(ctx.Headers.ToColoredJson())
return 200, hctypes.Dict{
"success": true,
"message": "OTP verified",
}, nil
}
```
func (config *Config) ToDict() hctypes.Dict
type ConfigAPI struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"`
ContentType string `json:"content_type,omitempty"`
ResponseType string `json:"response_type,omitempty"`
Timeout string `json:"timeout,omitempty"`
Callback *ConfigCallback `json:"callback,omitempty"`
Params []*validate.Options `json:"params,omitempty"`
URLParams []*validate.Options `json:"url_params,omitempty"`
ExtraConfig hctypes.Dict `json:"extra_config,omitempty"`
// contains filtered or unexported fields
}
func (config_api *ConfigAPI) ForPublic() *ConfigAPI
func (config_api *ConfigAPI) HTTPHandler(ctx *gin.Context)
func (config_api *ConfigAPI) HTTPHandlerConfig(ctx *gin.Context)
func (config_api *ConfigAPI) ToDict() hctypes.Dict
func (config_api *ConfigAPI) ValidParams(data hctypes.Dict) *ReturnError
func (config_api *ConfigAPI) ValidURLParams(data hctypes.Dict) *ReturnError
type ConfigCallback struct {
Plugin string `json:"plugin,omitempty"`
Function string `json:"function,omitempty"`
// contains filtered or unexported fields
}
type ConfigContext struct {
Method string `json:"method,omitempty"`
Url string `json:"url,omitempty"`
Config *Config `json:"config,omitempty"`
ConfigApi *ConfigAPI `json:"config_api,omitempty"`
URLParams hctypes.Dict `json:"url_params,omitempty"`
Params hctypes.Dict `json:"params,omitempty"`
Headers hctypes.Dict `json:"headers,omitempty"`
Request *http.Request `json:"-"`
Writer http.ResponseWriter `json:"-"`
}
func (ctx *ConfigContext) Error(status int, message string) (int, hctypes.Dict, *ReturnHTTPError)
type ConfigServer struct {
Port int `json:"port"`
}
type ConfigTemplate struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
FilePath string `json:"file_path,omitempty"`
Callback *ConfigTemplateCallback `json:"callback,omitempty"`
URLParams []*validate.Options `json:"url_params,omitempty"`
// contains filtered or unexported fields
}
func (config_template *ConfigTemplate) HTTPHandler(ctx *gin.Context)
type ConfigTemplateCallback struct {
Plugin string `json:"plugin,omitempty"`
Function string `json:"function,omitempty"`
// contains filtered or unexported fields
}
type ConfigTemplateContext struct {
Url string `json:"url,omitempty"`
Config *Config `json:"config,omitempty"`
ConfigTemplate *ConfigTemplate `json:"config_template,omitempty"`
URLParams hctypes.Dict `json:"url_params,omitempty"`
Headers hctypes.Dict `json:"headers,omitempty"`
Request *http.Request `json:"-"`
Writer http.ResponseWriter `json:"-"`
}
type ReturnError struct {
Name string `json:"name,omitempty"`
Errors interface{} `json:"errors,omitempty"`
}
type ReturnHTTPError struct {
StatusCode int `json:"status"`
Result hctypes.Dict `json:"result,omitempty"`
Errors []*ReturnError `json:"errors,omitempty"`
}
func DefaultCallbackAPIFunction(*ConfigContext) (int, hctypes.Dict, *ReturnHTTPError)
Template represents a mail template
type Template struct {
// contains filtered or unexported fields
}
func NewTemplate(template string) (*Template, error)
NewTemplate creates a new Template
template: The template Returns: *Template
func NewTemplateFromFile(template_file string) (*Template, error)
NewTeplateFromFile creates a new Template
template_file: The template file Returns: *Template
func (t *Template) Render(data hctypes.Dict) (string, error)
Render renders the template
data: The data Returns: string