generate

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package generate is to generate code, including model, cache, dao, handler, http, service, grpc, grpc-gw, grpc-cli code.

Index

Constants

View Source
const (

	// TplNameSponge name of the template
	TplNameSponge = "sponge"

	// DBDriverMysql mysql driver
	DBDriverMysql = "mysql"
	// DBDriverPostgresql postgresql driver
	DBDriverPostgresql = "postgresql"
	// DBDriverTidb tidb driver
	DBDriverTidb = "tidb"
	// DBDriverSqlite sqlite driver
	DBDriverSqlite = "sqlite"
	// DBDriverMongodb mongodb driver
	DBDriverMongodb = "mongodb"
)

Variables

View Source
var (
	ModelInitDBFile     = databaseInitDBFile
	ModelInitDBFileMark = databaseInitDBFileMark
	//AppConfigFileDBMark = appConfigFileMark2
	StartMark = startMark
	EndMark   = endMark
)
View Source
var (
	CurrentDbDriver = func(dbDriver string) string { return "// db driver is " + dbDriver }
)
View Source
var Replacers = map[string]replacer.Replacer{}

Replacers replacer name

View Source
var SpongeDir = getHomeDir() + gofile.GetPathDelimiter() + ".sponge"

SpongeDir sponge directory

Functions

func CacheCommand

func CacheCommand(parentName string) *cobra.Command

CacheCommand generate cache code

func ConfigCommand

func ConfigCommand() *cobra.Command

ConfigCommand convert yaml to struct command

func ConfigmapCommand

func ConfigmapCommand() *cobra.Command

ConfigmapCommand generate k8s configmap command

func DaoCommand

func DaoCommand(parentName string) *cobra.Command

DaoCommand generate dao code

func DeleteCodeMark

func DeleteCodeMark(r replacer.Replacer, filename string, startMark []byte, endMark []byte) []replacer.Field

DeleteCodeMark delete code mark fragment

func GRPCAndHTTPCommand added in v1.13.0

func GRPCAndHTTPCommand() *cobra.Command

GRPCAndHTTPCommand generate grpc+http servers code based on sql

func GRPCAndHTTPPbCommand

func GRPCAndHTTPPbCommand() *cobra.Command

GRPCAndHTTPPbCommand generate grpc+http servers code based on protobuf file

func GRPCConnectionCommand

func GRPCConnectionCommand() *cobra.Command

GRPCConnectionCommand generate grpc connection code

func GetDBConfigurationCode

func GetDBConfigurationCode(dbDriver string) string

GetDBConfigurationCode get db config code

func GetGoModFields

func GetGoModFields(moduleName string) []replacer.Field

GetGoModFields get go mod fields

func GetInitDataBaseCode

func GetInitDataBaseCode(dbDriver string) string

GetInitDataBaseCode get init db code

func HTTPCommand

func HTTPCommand() *cobra.Command

HTTPCommand generate web server code

func HTTPPbCommand

func HTTPPbCommand() *cobra.Command

HTTPPbCommand generate web server code based on protobuf file

func HandleSwaggerJSONCommand added in v1.14.0

func HandleSwaggerJSONCommand() *cobra.Command

HandleSwaggerJSONCommand handle swagger json command

func HandlerCommand

func HandlerCommand() *cobra.Command

HandlerCommand generate handler code

func HandlerPbCommand

func HandlerPbCommand() *cobra.Command

HandlerPbCommand generate handler and protobuf code

func Init

func Init() error

Init initializing the template

func InitFS

func InitFS(name string, filepath string, fs embed.FS)

InitFS initializing th FS templates

func ModelCommand

func ModelCommand(parentName string) *cobra.Command

ModelCommand generate model code

func ParseFuzzyProtobufFiles

func ParseFuzzyProtobufFiles(protobufFile string) ([]string, error)

ParseFuzzyProtobufFiles parse fuzzy protobuf files

func ProtobufCommand

func ProtobufCommand() *cobra.Command

ProtobufCommand generate protobuf code

func RPCCommand

func RPCCommand() *cobra.Command

RPCCommand generate grpc server code

func RPCGwPbCommand

func RPCGwPbCommand() *cobra.Command

RPCGwPbCommand generate grpc gateway server code base on protobuf file

func RPCPbCommand

func RPCPbCommand() *cobra.Command

RPCPbCommand generate grpc server code based on protobuf file

func ServiceAndHandlerCRUDCommand

func ServiceAndHandlerCRUDCommand() *cobra.Command

ServiceAndHandlerCRUDCommand generate both service and handler CRUD code

func ServiceCommand

func ServiceCommand() *cobra.Command

ServiceCommand generate service code

func SetSelectFiles

func SetSelectFiles(dbDriver string, selectFiles map[string][]string) error

nolint

func SubServerCodeFields

func SubServerCodeFields(moduleName string, serverName string) []replacer.Field

SubServerCodeFields sub server code fields

Types

type KeyValue added in v1.14.0

type KeyValue struct {
	Key   string
	Value interface{}
}

KeyValue represents a key-value pair for ordered JSON marshaling

type OrderedMap added in v1.14.0

type OrderedMap []KeyValue

OrderedMap is a slice of KeyValue pairs, representing an ordered JSON object.

func (OrderedMap) MarshalJSON added in v1.14.0

func (om OrderedMap) MarshalJSON() ([]byte, error)

MarshalJSON custom marshals OrderedMap to JSON, preserving key order.

type Template

type Template struct {
	Name     string
	FS       embed.FS
	FilePath string
}

Template information

type Version

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

Jump to

Keyboard shortcuts

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