stargo

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

Usage

main.go

import (
	"flag"
	"service/app/internal/server"
	pb "your/proto/path/v1"

	"github.com/starfork/stargo"
	"github.com/starfork/stargo/store/mysql"
	"github.com/starfork/stargo/store/redis"
	"google.golang.org/grpc/reflection"
)

func main() {
	cf := flag.String("c", "../../config/debug.yaml", "config file path")
	flag.Parse()
	sc := server.LoadConfig(*cf)
	c := sc.Server
	app := stargo.New(
		stargo.Org("park"),
		stargo.Name("app"),
		stargo.Config(sc.Server),
		stargo.UnaryInterceptor(your inteceprot1),
		stargo.UnaryInterceptor(your inteceprot2),
        ...
	)

	s := app.Server()
	if c.Environment == "debug" {
		reflection.Register(s)
	}
	pb.RegisterAppServer(s, server.New(app))
	app.Run()
}

server/handler.go

type handler struct {
	logger logger.Logger
	c      cache.Cache
	pb.UnimplementedAppServer
}

// New handler
func New(app *stargo.App) *handler {
    rdc:=app.Store("redis").(*redis.Redis).GetInstance()
	h := &handler{
		logger: app.GetLogger(),
		c:      credis.New(rdc),
	}
	return h
}

更多参考 stargo-examples

环境、工具

protobuf 安装


#Debian
apt-get install protobuf-compiler
#Ubuntu
apt-get install protobuf-compiler
#Alpine
apk add protobuf
#Arch Linux
pacman -S protobuf
#Kali Linux
apt-get install protobuf-compiler
#CentOS
yum install protobuf-compiler
#Fedora
dnf install protobuf-compiler

#OS X
brew install protobuf

#Raspbian
apt-get install protobuf-compiler

#Docker
docker run cmd.cat/protoc protoc

环境相关

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/favadi/protoc-go-inject-tag@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
go install golang.org/x/tools/cmd/stringer@latest
go install github.com/infobloxopen/protoc-gen-gorm@latest

工具相关

grpc-client-cli 命令行调试工具
go install github.com/vadimi/grpc-client-cli/cmd/grpc-client-cli@latest

vscocde 插件
go install github.com/yoheimuta/protolint/cmd/protolint@latest
gostar 项目生成工具
go install  github.com/starfork/gostar@latest
相关库
slice 操作相关

https://github.com/starfork/go-slice

加密

https://github.com/starfork/go-crypto

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Tz *time.Location
	// contains filtered or unexported fields
}

App App

func New

func New(opt ...Option) *App

func (*App) Broker added in v0.1.1

func (s *App) Broker() broker.Broker

func (*App) Client added in v0.1.3

func (s *App) Client() *client.Client

func (*App) Config added in v0.1.1

func (s *App) Config() *config.Config

func (*App) Init added in v0.1.3

func (s *App) Init()

func (*App) Logger added in v0.1.1

func (s *App) Logger(l ...logger.Logger) logger.Logger

func (*App) Registry added in v0.1.1

func (s *App) Registry() naming.Registry

func (*App) Resolver added in v0.1.3

func (s *App) Resolver() naming.Resolver

func (*App) Restart

func (s *App) Restart()

Restart server

func (*App) RpcServer added in v0.1.1

func (s *App) RpcServer() *grpc.Server

// Server

func (*App) Run

func (s *App) Run()

Run server

func (*App) Service added in v0.0.3

func (s *App) Service() naming.Service

返回标准服务格式

func (*App) Stop

func (s *App) Stop()

Stop server

func (*App) Store added in v0.0.6

func (s *App) Store(name string, st ...store.Store) store.Store

获取或者创建一个store

func (*App) Tracer added in v0.2.1

func (s *App) Tracer() tracer.Tracer

type Option

type Option func(o *Options)

Option Option

func WithAddr added in v0.1.1

func WithAddr(c string) Option

func WithConfig added in v0.1.1

func WithConfig(c *config.Config) Option

func WithName added in v0.1.1

func WithName(c string) Option

func WithOrg added in v0.1.1

func WithOrg(c string) Option

func WithServer added in v0.1.1

func WithServer(opt ...grpc.ServerOption) Option

Server option

func WithStreamnIterceptor added in v0.1.1

func WithStreamnIterceptor(opt grpc.StreamServerInterceptor) Option

StreamInterceptor Stream server interceptor

func WithTimezome added in v0.1.1

func WithTimezome(c string) Option

func WithUnaryInterceptor added in v0.1.1

func WithUnaryInterceptor(opt grpc.UnaryServerInterceptor) Option

UnaryInterceptor Unary server interceptor

type Options

type Options struct {
	Org, Name, Addr   string
	Config            *config.Config
	UnaryInterceptor  []grpc.UnaryServerInterceptor
	StreamInterceptor []grpc.StreamServerInterceptor
	Server            []grpc.ServerOption
	Timezone          string
}

Options 参数

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions default options

Directories

Path Synopsis
interceptor
ratelimit
Package ratelimit provides an efficient token bucket implementation that can be used to limit the rate of arbitrary things.
Package ratelimit provides an efficient token bucket implementation that can be used to limit the rate of arbitrary things.
util
geo

Jump to

Keyboard shortcuts

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