Categorygithub.com/go-ginseng/ginseng
modulepackage
1.4.5
Repository: https://github.com/go-ginseng/ginseng.git
Documentation: pkg.go.dev

# README

Ginseng

Ginseng is a core go backend engine based on gin.

Installation

go get -u github.com/go-ginseng/ginseng

Define your package

package plugin

import "github.com/go-ginseng/ginseng"

const PluginID = "2141b9a1-f505-44c2-85a7-9a8c972e2d7d"

type HelloWorldRequest struct {
    Name string `json:"name"`
}

type HelloWorldOption struct {
    Language string `json:"language"`
}

var language = "en"

func HelloWorldHandler(ctx *ginseng.Context[HelloWorldRequest]) {
    switch language {
    case "en":
        ctx.GinCtx().JSON(200, gin.H{"message": "Hello " + ctx.Request.Name})
    case "zh":
        ctx.GinCtx().JSON(200, gin.H{"message": "你好 " + ctx.Request.Name})
    }
}

func RegisterHandler(e *ginseng.Engine, option *HelloWorldOption) {
    language = option.Language
    ginseng.Get(e, "/hello", HelloWorldHandler)
}

Setup your engine

package main

import (
    "github.com/go-ginseng/ginseng"
    "plugin"
)

func main() {
    e := ginseng.NewEngine()
    e.Register(e, plugin.PluginID, plugin.RegisterHandler, &plugin.HelloWorldOption{
        Language: "en",
    })
    e.Run("127.0.0.1:5000")
}

# Functions

Delete setup the DELETE route.
Get setup the GET route.
NewEngine create a new engine.
Post
Post setup the POST route.
Put setup the PUT route.
Register is used to register/install a plugins Each plugin should expose this function and its option type The exposed function should be named as "RegisterHandler" Each plugin should expose a const string to identify itself, which should be named as "PluginID".

# Structs

Ginseng context This context is based on the Gin context.
Ginseng core engine This engine is based on the Gin framework.

# Type aliases

Ginseng handler function.
RegisterHandlerFunc is used to register/install a plugins Each plugin should expose this function and its option type The exposed function should be named as "RegisterHandler" Each plugin should expose a const string to identify itself, which should be named as "PluginID" RegisterHandlerFunc of packages should not have dependencies on each other.