letgo

package module
v0.0.0-...-ca36184 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 14 Imported by: 0

README

letgo

Let's Go.

渐进式的 go 轮子.

技能栈

结构

  • app - 应用层
  • conf - 配置层
  • store - 存储层
  • util - 工具层

app

应用层, 对外提供具体的应用程序.

常见的应用程序:

  • CLI - 命令行接口
  • API - 应用程序接口 (Rest/RPC/WebService/...)
  • Web - 网站
  • Client - 客户端程序 (PC/Mobile App)
  • ...

参数选项支持优先级:命令行参数 > 配置文件参数 > WithXXX()函数选项 > 内置默认值.

conf

配置层, 提供统一的配置操作.

常见的配置文件:

  • ini
  • xml
  • json
  • yml
  • ...

store

存储层, 对外提供持久化相关的操作, 但不暴露任何具体的数据库对象.

我们所说的持久化通常是把数据存储到某个地方, 比如:

  • memory
  • sqlite
  • oracle
  • mssql
  • mysql
  • pgsql
  • tidb
  • redis
  • ...

所以如果需要切换数据库, 可以自行调整内部实现.

这样外部导入时通常是下面这样的, 也不需要单独实例化一个操作的结构体.

import (	
	userStore "github.com/taadis/store/user"
	orderStore "github.com/taadis/store/order"
)

util

工具层, 封装一些小工具都放到这里, 方便使用.

...

Documentation

Overview

doc.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(configStruct interface{}, sources ...ConfigSource) error

LoadConfig 支持多配置源加载 sources: 配置源实例(按优先级排序) configStruct: 目标配置结构体指针

Types

type App

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

func NewApp

func NewApp(opts ...Option) *App

func (*App) Load

func (a *App) Load(v any) error

func (*App) Run

func (a *App) Run(ctx context.Context) error

type Application

type Application interface {
	Load(v any) error
	Run(ctx context.Context) error
}

type ConfigSource

type ConfigSource interface {
	Load() (config.Config, error)
	Priority() int // 配置源优先级(数字越大优先级越高)
}

ConfigSource 定义配置源接口

type FileSource

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

FileSource 本地文件配置源

func NewFileSource

func NewFileSource(path string) *FileSource

func (*FileSource) Load

func (s *FileSource) Load() (config.Config, error)

func (*FileSource) Priority

func (s *FileSource) Priority() int

type Option

type Option func(*Options)

Option 定义配置选项函数

func RegistrarTimeout

func RegistrarTimeout(t time.Duration) Option

RegistrarTimeout with registrar timeout.

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout with app stop timeout.

func WithConfigName

func WithConfigName(name string) Option

WithConfigName 设置配置文件名称 比如:你的配置文件是config.yaml,这里name=config

func WithContext

func WithContext(ctx context.Context) Option

WithContext with service context.

func WithEndpoint

func WithEndpoint(endpoints ...*url.URL) Option

WithEndpoint with service endpoint.

func WithEnv

func WithEnv(env string) Option

WithEnv 设置运行环境

func WithID

func WithID(id string) Option

WithID 设置应用 ID

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger with service logger.

func WithMetadata

func WithMetadata(metadata map[string]string) Option

WithMetadata with service metadata.

func WithName

func WithName(name string) Option

WithName 设置应用名称

func WithPort

func WithPort(port int) Option

WithPort 设置服务端口

func WithRegistrar

func WithRegistrar(r registry.Registrar) Option

WithRegistrar with service registry.

func WithServer

func WithServer(servers ...transport.Server) Option

WithServer with transport servers.

func WithSignal

func WithSignal(sigs ...os.Signal) Option

WithSignal with exit signals.

func WithVersion

func WithVersion(version string) Option

WithVersion 设置应用版本

type Options

type Options struct {

	//koptions   []kratos.Option
	ConfigName string
	Env        string
	Port       int
	Config     interface{} // 项目的配置结构体
	// contains filtered or unexported fields
}

Options 存储应用配置参数 ref:https://github.com/go-kratos/kratos/blob/main/options.go

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions 创建 Options 实例,应用默认值

Directories

Path Synopsis
数组和切片
数组和切片
ai-go command
ai-go project main.go
ai-go project main.go
beego command
concurrent
concurrent Go 语言并发编程的一些案例...
concurrent Go 语言并发编程的一些案例...
json command
jwt command
keywords/defer command
defer_defer.go http://go.jsrun.net/k9yKp
defer_defer.go http://go.jsrun.net/k9yKp
others command
Q: 使用两个goroutine交替打印序列,一个goroutinue打印数字,另一个goroutine打印字母,最终结果如下: 12AB34CD56EF78GH910IJ 参考: https://www.cnblogs.com/zhangjinfu/p/11288472.html 网上答案很多, 这个是比较简洁明了滴
Q: 使用两个goroutine交替打印序列,一个goroutinue打印数字,另一个goroutine打印字母,最终结果如下: 12AB34CD56EF78GH910IJ 参考: https://www.cnblogs.com/zhangjinfu/p/11288472.html 网上答案很多, 这个是比较简洁明了滴
xml command
api
resolver
Package resolver resolves a http request to an endpoint
Package resolver resolves a http request to an endpoint
resolver/grpc
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
resolver/host
Package host resolves using http host
Package host resolves using http host
resolver/path
Package path resolves using http path
Package path resolves using http path
resolver/vpath
Package vpath resolves using http path and recognised versioned urls
Package vpath resolves using http path and recognised versioned urls
app
clock command
echo-server command
filesvr command
forward command
generator command
golb command
app/golb/main.go
app/golb/main.go
golb/vm
register.go
register.go
hello command
app/hello/main.go
app/hello/main.go
letgo command
main.go
main.go
rpc/client command
rpc/server command
test command
app/test/main.go
app/test/main.go
di module
gui/chapter03 module
i18n module
oauthx module
snaker module
stdlog module
toolkit module
plugin/memory module
gob
xml
Package errors The error is normally JSON encoded.
Package errors The error is normally JSON encoded.
faq
Package gobyexample https://gobyexample.com/ https://gobyexample-cn.github.io/ https://go.dev/play/
Package gobyexample https://gobyexample.com/ https://gobyexample-cn.github.io/ https://go.dev/play/
exit command
httpclient command
gof
handler
internal
service
Package service
Package service
tests
Package tests 用来提供一些测试示例,基于一下准则 1.不依赖三方库,尽量只用标准库来实现功能示例 2...
Package tests 用来提供一些测试示例,基于一下准则 1.不依赖三方库,尽量只用标准库来实现功能示例 2...
math 是对标准包 math 的一些补充, 以便使用.
math 是对标准包 math 的一些补充, 以便使用.
Package metadata is a way of defining message headers.
Package metadata is a way of defining message headers.
middleware
net
http
http.go
http.go
rpc
rpc = Remote Procedure Call 也就是我们熟称的 "远程过程调用"
rpc = Remote Procedure Call 也就是我们熟称的 "远程过程调用"
plugin
hello command
main.go
main.go
Package registry is an interface for service registry and discovery.
Package registry is an interface for service registry and discovery.
mdns_registry
Package mdns_registry provides a multicast dns registry.
Package mdns_registry provides a multicast dns registry.
Package server
Package server
util
jwt

Jump to

Keyboard shortcuts

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