...

Source file src/gitlab.hexacode.org/go-libs/microservice/main.go

Documentation: gitlab.hexacode.org/go-libs/microservice

     1  /*
     2   * Micro Service
     3   * Package: gitlab.hexacode.org/go-libs/microservice
     4   * Maintainer: Azzis Arswendo <azzis@hexacode.org>
     5   *
     6   * Copyright (C) 2023 Hexacode Teknologi Indonesia
     7   * All Rights Reserved
     8   */
     9  
    10  // Command: microservice
    11  //
    12  // Description: Micro Service
    13  //
    14  // Usage: microservice
    15  //
    16  // Example: ./config.json
    17  //
    18  // ```json
    19  //
    20  //	{
    21  //	    "namespace": "api-registration",
    22  //	    "server": {
    23  //	        "port": 8080
    24  //	    },
    25  //		"templates": [
    26  //			{
    27  //				"name": "registration",
    28  //				"path": "/",
    29  //				"file_path": "example/template.html"
    30  //			}
    31  //		],
    32  //	    "apis": [
    33  //	        {
    34  //	            "name": "registration",
    35  //	            "path": "/registration",
    36  //	            "method": "POST",
    37  //	            "content_type": "application/json",
    38  //	            "response_type": "application/json",
    39  //	            "callback": {
    40  //	                "plugin": "plugin.so",
    41  //	                "function": "Registration"
    42  //	            },
    43  //	            "params": [
    44  //	                {
    45  //	                    "name": "username",
    46  //	                    "label": "Username",
    47  //	                    "placeholder": "Enter Username",
    48  //	                    "type": "username",
    49  //	                    "validate": "username",
    50  //	                    "required": true,
    51  //	                    "min": 5,
    52  //	                    "max": 32
    53  //	                },
    54  //	                {
    55  //	                    "name": "fullname",
    56  //	                    "label": "Full Name",
    57  //	                    "placeholder": "Enter Full Name",
    58  //	                    "type": "name",
    59  //	                    "validate": "name",
    60  //	                    "required": true,
    61  //	                    "min": 5,
    62  //	                    "max": 32
    63  //	                },
    64  //	                {
    65  //	                    "name": "email",
    66  //	                    "label": "Email Address",
    67  //	                    "placeholder": "Enter Email Address",
    68  //	                    "type": "email",
    69  //	                    "required": true,
    70  //	                    "min": 5,
    71  //	                    "max": 32
    72  //	                },
    73  //	                {
    74  //	                    "name": "password",
    75  //	                    "label": "Password",
    76  //	                    "placeholder": "Enter Password",
    77  //	                    "type": "password",
    78  //	                    "required": true,
    79  //	                    "min": 8,
    80  //	                    "max": 120
    81  //	                },
    82  //	                {
    83  //	                    "name": "confirm_password",
    84  //	                    "label": "Confirm Password",
    85  //	                    "placeholder": "Enter Confirm Password",
    86  //	                    "type": "password",
    87  //	                    "required": true,
    88  //	                    "min": 8,
    89  //	                    "max": 120
    90  //	                }
    91  //	            ]
    92  //	        },
    93  //	        {
    94  //	            "name": "verification",
    95  //	            "path": "/verification/:id/:otp",
    96  //	            "method": "GET",
    97  //	            "content_type": "application/json",
    98  //	            "response_type": "application/json",
    99  //	            "callback": {
   100  //	                "plugin": "plugin.so",
   101  //	                "function": "Verification"
   102  //	            },
   103  //	            "url_params": [
   104  //	                {
   105  //	                    "name": "id",
   106  //	                    "type": "textnumber",
   107  //	                    "required": true
   108  //	                },
   109  //	                {
   110  //	                    "name": "otp",
   111  //	                    "type": "textnumber",
   112  //	                    "required": true
   113  //	                }
   114  //	            ]
   115  //	        }
   116  //	    ]
   117  //	}
   118  //
   119  // ```
   120  //
   121  // Example: main.go
   122  //
   123  // ```go
   124  //
   125  //	package main
   126  //
   127  //	import (
   128  //	  "fmt"
   129  //
   130  //	  "gitlab.hexacode.org/go-libs/hctypes"
   131  //	  "gitlab.hexacode.org/go-libs/microservice/config"
   132  //	)
   133  //
   134  //	func Registration(ctx *config.ConfigContext) (int, hctypes.Dict, *config.ReturnHTTP) {
   135  //	  fmt.Println(ctx.Config.ToDict().ToColoredJson())
   136  //	  fmt.Println(ctx.ConfigApi.ToDict().ToColoredJson())
   137  //	  fmt.Println(ctx.URLParams.ToColoredJson())
   138  //	  fmt.Println(ctx.Params.ToColoredJson())
   139  //	  fmt.Println(ctx.Headers.ToColoredJson())
   140  //
   141  //	  return 200, hctypes.Dict{
   142  //	    "id":  1,
   143  //	    "otp": 123456,
   144  //	  }, nil
   145  //	}
   146  //
   147  //	func Verification(ctx *config.ConfigContext) (int, hctypes.Dict, *config.ReturnHTTP) {
   148  //	  fmt.Println(ctx.Config.ToDict().ToColoredJson())
   149  //	  fmt.Println(ctx.ConfigApi.ToDict().ToColoredJson())
   150  //	  fmt.Println(ctx.URLParams.ToColoredJson())
   151  //	  fmt.Println(ctx.Params.ToColoredJson())
   152  //	  fmt.Println(ctx.Headers.ToColoredJson())
   153  //
   154  //	  return 200, hctypes.Dict{
   155  //	    "success": true,
   156  //	    "message": "OTP verified",
   157  //	  }, nil
   158  //	}
   159  //
   160  // ```
   161  package main
   162  
   163  import "gitlab.hexacode.org/go-libs/microservice/config"
   164  
   165  func main() {
   166  	conf, err := config.LoadConfig()
   167  	if err != nil {
   168  		panic(err)
   169  	}
   170  
   171  	conf.Run()
   172  }
   173  

View as plain text