gtag

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 2 Imported by: 47

Documentation

Overview

Package gtag providing tag content storing for struct.

Note that calling functions of this package is not concurrently safe, which means you cannot call them in runtime but in boot procedure.

Index

Examples

Constants

View Source
const (
	Default           = "default"      // Default value tag of struct field for receiving parameters from HTTP request.
	DefaultShort      = "d"            // Short name of Default.
	Param             = "param"        // Parameter name for converting certain parameter to specified struct field.
	ParamShort        = "p"            // Short name of Param.
	Valid             = "valid"        // Validation rule tag for struct of field.
	ValidShort        = "v"            // Short name of Valid.
	NoValidation      = "nv"           // No validation for specified struct/field.
	ORM               = "orm"          // ORM tag for ORM feature, which performs different features according scenarios.
	Arg               = "arg"          // Arg tag for struct, usually for command argument option.
	Brief             = "brief"        // Brief tag for struct, usually be considered as summary.
	Root              = "root"         // Root tag for struct, usually for nested commands management.
	Additional        = "additional"   // Additional tag for struct, usually for additional description of command.
	AdditionalShort   = "ad"           // Short name of Additional.
	Path              = `path`         // Route path for HTTP request.
	Method            = `method`       // Route method for HTTP request.
	Domain            = `domain`       // Route domain for HTTP request.
	Mime              = `mime`         // MIME type for HTTP request/response.
	Consumes          = `consumes`     // MIME type for HTTP request.
	Summary           = `summary`      // Summary for struct, usually for OpenAPI in request struct.
	SummaryShort      = `sm`           // Short name of Summary.
	SummaryShort2     = `sum`          // Short name of Summary.
	Description       = `description`  // Description for struct, usually for OpenAPI in request struct.
	DescriptionShort  = `dc`           // Short name of Description.
	DescriptionShort2 = `des`          // Short name of Description.
	Example           = `example`      // Example for struct, usually for OpenAPI in request struct.
	ExampleShort      = `eg`           // Short name of Example.
	Examples          = `examples`     // Examples for struct, usually for OpenAPI in request struct.
	ExamplesShort     = `egs`          // Short name of Examples.
	ExternalDocs      = `externalDocs` // External docs for struct, always for OpenAPI in request struct.
	ExternalDocsShort = `ed`           // Short name of ExternalDocs.
	GConv             = "gconv"        // GConv defines the converting target name for specified struct field.
	GConvShort        = "c"            // GConv defines the converting target name for specified struct field.
	Json              = "json"         // Json tag is supported by stdlib.
)

Variables

This section is empty.

Functions

func Get

func Get(name string) string

Get retrieves and returns the stored tag content for specified name.

func Parse

func Parse(content string) string

Parse parses and returns the content by replacing all tag name variable to its content for given `content`. Eg: gtag.Set("demo", "content") Parse(`This is {demo}`) -> `This is content`.

func Set

func Set(name, value string)

Set sets tag content for specified name. Note that it panics if `name` already exists.

Example
package main

import (
	"fmt"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/util/gmeta"
	"github.com/gogf/gf/v2/util/gtag"
)

func main() {
	type User struct {
		g.Meta `name:"User Struct" description:"{UserDescription}"`
	}
	gtag.Sets(g.MapStrStr{
		`UserDescription`: `This is a demo struct named "User Struct"`,
	})
	fmt.Println(gmeta.Get(User{}, `description`))

}
Output:

This is a demo struct named "User Struct"

func SetOver added in v2.1.0

func SetOver(name, value string)

SetOver performs as Set, but it overwrites the old value if `name` already exists.

func Sets

func Sets(m map[string]string)

Sets sets multiple tag content by map.

func SetsOver added in v2.1.0

func SetsOver(m map[string]string)

SetsOver performs as Sets, but it overwrites the old value if `name` already exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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