...

Package config

import "gitlab.hexacode.org/go-libs/microservice/config"
Overview
Index

Overview ▾

Index ▾

func DefaultCallbackTemplateFunction(*ConfigTemplateContext) hctypes.Dict
func Schedule(host string, module_manager_url string)
type Config
    func LoadConfig() (*Config, error)
    func (config *Config) ForPublic() *Config
    func (conf *Config) LoadOptionsStrapiSchemas() map[string]string
    func (config *Config) LoadPlugin() error
    func (config *Config) Run()
    func (config *Config) ToDict() hctypes.Dict
type ConfigAPI
    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
type ConfigContext
    func (ctx *ConfigContext) Error(status int, message string) (int, hctypes.Dict, *ReturnHTTPError)
type ConfigServer
type ConfigTemplate
    func (config_template *ConfigTemplate) HTTPHandler(ctx *gin.Context)
type ConfigTemplateCallback
type ConfigTemplateContext
type ReturnError
type ReturnHTTPError
    func DefaultCallbackAPIFunction(*ConfigContext) (int, hctypes.Dict, *ReturnHTTPError)
type Template
    func NewTemplate(template string) (*Template, error)
    func NewTemplateFromFile(template_file string) (*Template, error)
    func (t *Template) Render(data hctypes.Dict) (string, error)

Package files

config.go config_api.go config_callback.go config_callback_default.go config_option_strapi_schemas.go config_server.go config_template.go config_template_callback.go template.go

func DefaultCallbackTemplateFunction

func DefaultCallbackTemplateFunction(*ConfigTemplateContext) hctypes.Dict

func Schedule

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

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

func LoadConfig() (*Config, error)

func (*Config) ForPublic

func (config *Config) ForPublic() *Config

func (*Config) LoadOptionsStrapiSchemas

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) LoadPlugin

func (config *Config) LoadPlugin() error

func (*Config) Run

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) ToDict

func (config *Config) ToDict() hctypes.Dict

type ConfigAPI

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 (*ConfigAPI) ForPublic

func (config_api *ConfigAPI) ForPublic() *ConfigAPI

func (*ConfigAPI) HTTPHandler

func (config_api *ConfigAPI) HTTPHandler(ctx *gin.Context)

func (*ConfigAPI) HTTPHandlerConfig

func (config_api *ConfigAPI) HTTPHandlerConfig(ctx *gin.Context)

func (*ConfigAPI) ToDict

func (config_api *ConfigAPI) ToDict() hctypes.Dict

func (*ConfigAPI) ValidParams

func (config_api *ConfigAPI) ValidParams(data hctypes.Dict) *ReturnError

func (*ConfigAPI) ValidURLParams

func (config_api *ConfigAPI) ValidURLParams(data hctypes.Dict) *ReturnError

type ConfigCallback

type ConfigCallback struct {
    Plugin   string `json:"plugin,omitempty"`
    Function string `json:"function,omitempty"`
    // contains filtered or unexported fields
}

type ConfigContext

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 (*ConfigContext) Error

func (ctx *ConfigContext) Error(status int, message string) (int, hctypes.Dict, *ReturnHTTPError)

type ConfigServer

type ConfigServer struct {
    Port int `json:"port"`
}

type ConfigTemplate

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 (*ConfigTemplate) HTTPHandler

func (config_template *ConfigTemplate) HTTPHandler(ctx *gin.Context)

type ConfigTemplateCallback

type ConfigTemplateCallback struct {
    Plugin   string `json:"plugin,omitempty"`
    Function string `json:"function,omitempty"`
    // contains filtered or unexported fields
}

type ConfigTemplateContext

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

type ReturnError struct {
    Name   string      `json:"name,omitempty"`
    Errors interface{} `json:"errors,omitempty"`
}

type ReturnHTTPError

type ReturnHTTPError struct {
    StatusCode int            `json:"status"`
    Result     hctypes.Dict   `json:"result,omitempty"`
    Errors     []*ReturnError `json:"errors,omitempty"`
}

func DefaultCallbackAPIFunction

func DefaultCallbackAPIFunction(*ConfigContext) (int, hctypes.Dict, *ReturnHTTPError)

type Template

Template represents a mail template

type Template struct {
    // contains filtered or unexported fields
}

func NewTemplate

func NewTemplate(template string) (*Template, error)

NewTemplate creates a new Template

template: The template Returns: *Template

func NewTemplateFromFile

func NewTemplateFromFile(template_file string) (*Template, error)

NewTeplateFromFile creates a new Template

template_file: The template file Returns: *Template

func (*Template) Render

func (t *Template) Render(data hctypes.Dict) (string, error)

Render renders the template

data: The data Returns: string