KataGin

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2021 License: GPL-3.0 Imports: 13 Imported by: 1

README

Kata-Gin

Package for Gin. Automatic generation of route maps

How to use this package?

  • Declare a struct and implement some gin functions like this:
package main

import (
	"net/http"

	kg "github.com/KataSpace/Kata-Gin"
	"github.com/gin-gonic/gin"
)

type example struct{}

func (e *example) GetAllName(c *gin.Context) {
	c.JSON(http.StatusOK, "Response by GetAllName")
}

func main() {
	r := gin.Default()
	r = kg.RegisterRouter(r, nil, nil, new(example))

	r.Run()
}

Kata-Gin will register GetAllName in Gin like the follow:

GET /AllName  GetAllName

If there has a request curl http://127.0.0.1:8080/AllName, then get response: Response by GetAllName

Details about KataGin

  • name convert function
  1. slashConvert

If there are multiple consecutive uppercase letters in the function name, it will be ignored by default. If user wants to keep these uppercase letters, can use this function.

This function will add slash before every upper letter. It uses regex([A-Z][a-z]+|([A-Z]|[0-9]){%d},%d is n value.) for split string.

As I test, n = 3 gets the better effects.

If user set n = -1, then ignore this feature. e.g.

n == -1
AAAGetAllName ==> Get/All/Name

n == 2
GetAPIAllName ==> Get/AP/IA/Name

n == 3
GetAPIAllName ==> Get/API/All/Name

n == 10
GetAPIAllName ==> Get/All/Name

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentConvert

func CommentConvert(name, comment string) string

CommentConvert get api uri from comment There are has three conditions 1. // Hello function Hello(){} will convert to GET /Hello 2. // Hello // GET / will convert to GET /Hello 3. // Hello // GET /v1 will conver to GET /v1/Hello

func CommentGetMethods

func CommentGetMethods(s string) (method string, name string)

CommentGetMethods Spilt method and path from url Method and uri path must use space isolation e.g. GET /v1/Hello ==> GET /v1/Hello

func DefaultConvert added in v0.2.0

func DefaultConvert(name string) string

func DefaultGetMethods added in v0.2.0

func DefaultGetMethods(s string) (method string, name string)

func RegisterRouter

func RegisterRouter(r *gin.Engine, nameConvert func(string) string, getMethods func(string) (string, string), objects ...interface{}) *gin.Engine

func SlashConvertWithFive

func SlashConvertWithFive(s string) string

func SlashConvertWithOne

func SlashConvertWithOne(s string) string

func SlashConvertWithTen

func SlashConvertWithTen(s string) string

func SlashConvertWithThree

func SlashConvertWithThree(s string) string

func SlashConvertWithTwo

func SlashConvertWithTwo(s string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL