Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Mar 13, 2021
1 parent dd3be34 commit 6b98400
Show file tree
Hide file tree
Showing 73 changed files with 4,590 additions and 3,460 deletions.
97 changes: 82 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
WORKDIR=`pwd`
Project=github.com/pubgo/golug
GOPath=$(shell go env GOPATH)
Version=$(shell git tag --sort=committerdate | tail -n 1)
GoROOT=$(shell go env GOROOT)
BuildTime=$(shell date "+%F %T")
CommitID=$(shell git rev-parse HEAD)
LDFLAGS=-ldflags " \
-X '${Project}/golug_version.GoROOT=${GoROOT}' \
-X '${Project}/golug_version.BuildTime=${BuildTime}' \
-X '${Project}/golug_version.GoPath=${GOPath}' \
-X '${Project}/golug_version.CommitID=${CommitID}' \
-X '${Project}/golug_version.Project=${Project}' \
-X '${Project}/golug_version.Version=${Version:-v0.0.1}' \
-X '${Project}/version.GoROOT=${GoROOT}' \
-X '${Project}/version.BuildTime=${BuildTime}' \
-X '${Project}/version.GoPath=${GOPath}' \
-X '${Project}/version.CommitID=${CommitID}' \
-X '${Project}/version.Project=${Project}' \
-X '${Project}/version.Version=${Version}' \
"

default: run

.PHONY: build
build:
@go build ${LDFLAGS} -mod vendor -v -o main cmds/golug/main.go

build_hello_test:
@go build ${LDFLAGS} -mod vendor -v -o main example/hello/main.go

.PHONY: install
install:
@cd cmds/golug && go install -v ${LDFLAGS} .

.PHONY: test
test:
@go test -race -v ./... -cover
@go test -short -race -v ./... -cover

.PHONY: proto
proto: clear gen
Expand All @@ -36,23 +35,25 @@ proto: clear gen
-I${GOPATH}/src/github.com/googleapis/googleapis \
-I${GOPATH}/src/github.com/gogo/protobuf \
--go_out=plugins=grpc:. \
--go_opt=paths=source_relative \
--grpc-gateway_out=. \
--grpc-gateway_opt=paths=source_relative \
--grpc-gateway_opt=logtostderr=true \
--golug_out=. \
example/proto/hello/*
example/proto/hello/*.proto

protoc -I. \
-I/usr/local/include \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/googleapis/googleapis \
-I${GOPATH}/src/github.com/gogo/protobuf \
--go_out=plugins=grpc:. \
--go_opt=paths=source_relative \
--grpc-gateway_out=. \
--grpc-gateway_opt=paths=source_relative \
--grpc-gateway_opt=logtostderr=true \
--golug_out=. \
example/proto/login/*
example/proto/login/*.proto

.PHONY: clear
clear:
Expand All @@ -65,7 +66,73 @@ gen:

.PHONY: example
example:
go build ${LDFLAGS} -mod vendor -v -o main example/main.go
go build ${LDFLAGS} -mod vendor -v -o main example/*.go

.PHONY: run
run:
go run ${LDFLAGS} -mod vendor -v example/*.go http

docker:
docker build -t golug .
docker build -t golug .

build-all:
go build -tags "kcp quic" ./...

deps:
go list -f '{{ join .Deps "\n"}}' ./... |grep "/" | grep -v "github.com/smallnest/rpcx"| grep "\." | sort |uniq

vet:
go vet ./...

tools:
go install \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/golang/lint/golint \

cover:
gocov test -tags "kcp quic" ./... | gocov-html > cover.html
open cover.html

check-libs:
GIT_TERMINAL_PROMPT=1 GO111MODULE=on go list -m -u all | column -t

update-libs:
GIT_TERMINAL_PROMPT=1 GO111MODULE=on go get -u -v ./...

mod-tidy:
GIT_TERMINAL_PROMPT=1 GO111MODULE=on go mod tidy

install:
@echo "libprotoc 3.11.4"
go install \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/bufbuild/buf/cmd/buf \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
github.com/golang/protobuf/protoc-gen-go \

mac:
GOOS=darwin go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl-darwin goctl.go
$(if $(shell command -v upx), upx goctl-darwin)
win:
GOOS=windows go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl.exe goctl.go
$(if $(shell command -v upx), upx goctl.exe)
linux:
GOOS=linux go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl-linux goctl.go
$(if $(shell command -v upx), upx goctl-linux)

changelog:
docker run --rm \
--interactive \
--tty \
-e "CHANGELOG_GITHUB_TOKEN=${CHANGELOG_GITHUB_TOKEN}" \
-v "$(PWD):/usr/local/src/your-app" \
ferrarimarco/github-changelog-generator:1.14.3 \
-u grpc-ecosystem \
-p grpc-gateway \
--author \
--compare-link \
--github-site=https://github.com \
--unreleased-label "**Next release**" \
--release-branch=master \
--future-release=v2.3.0
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# [golug](https://www.notion.so/barrylog/golug-96142de3b0444b6c905886efac96eeb0)

1. protoc
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip
go get github.com/golang/protobuf/[email protected]
go install -v github.com/gogo/protobuf/protoc-gen-gofast
go install -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go install -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install -v github.com/vektra/mockery/cmd/mockery


1. golug是一个高度抽象和集成的微服务框架
2. golug集成了config, log, command, plugin, grpc, http(fiber), task, broker等组件
3. golug使用方便, 统一入口
Expand Down Expand Up @@ -74,3 +83,7 @@ func main() {
))
}
```


https://github.com/fullstorydev/grpcurl
https://github.com/bojand/ghz
2 changes: 1 addition & 1 deletion broker/abc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SubOpts struct {
Broker Broker
}

type Handler func(*Message) error
type Handler func(msg *Message) error
type Message struct {
Header map[string]string
ID string
Expand Down
6 changes: 2 additions & 4 deletions broker/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ func onInit(ent interface{}) {
driver := cfg.Driver
xerror.Assert(driver == "", "broker driver is null")
xerror.Assert(!factories.Has(driver), "broker driver %s not found", driver)
xerror.Assert(brokers.Has(name), "broker %s already exists", name)

fc := factories.Get(driver).(Factory)
var brk = xerror.PanicErr(fc(config.Map(Name, name))).(Broker)

xerror.Assert(brokers.Has(name), "broker %s driver %s already exists", name, driver)
brokers.Set(name, brk)
brokers.Set(name, xerror.PanicErr(fc(config.Map(Name, name))).(Broker))
}
}

Expand Down
6 changes: 2 additions & 4 deletions client/grpclient/balancer/resolver/discovbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ func (d *discovBuilder) getAddrs() []resolver.Address {
func (d *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
// target.Authority得到注册中心的地址
// 当然也可以直接通过全局变量[registry.Default]获取注册中心, 然后进行判断
var r = registry.Get(target.Authority)
if r == nil {
return nil, fmt.Errorf("registry %s not exists\n", target.Authority)
}
var r = registry.Default
xerror.Assert(r == nil, "registry %s not found", target.Authority)

// target.Endpoint是服务的名字, 是项目启动的时候注册中心中注册的项目名字
// GetService根据服务名字获取注册中心该项目所有服务
Expand Down
75 changes: 74 additions & 1 deletion cmds/protoc-gen-golug/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 0 additions & 54 deletions cmds/protoc-gen-golug/tpl.go

This file was deleted.

4 changes: 4 additions & 0 deletions config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ var (
EnvPrefix = "golug"
CatchSigpipe = true
Trace = false
Port = 8080
Home = filepath.Join(xerror.PanicStr(filepath.Abs(filepath.Dir(""))), "home")
Project = "golug"
Level = "debug"
Mode = RunMode.Dev
Signal os.Signal = syscall.Signal(0)
// RunEnvMode 项目运行模式
Expand Down Expand Up @@ -61,6 +63,8 @@ func init() {

func DefaultFlags() *pflag.FlagSet {
flags := pflag.NewFlagSet("app", pflag.PanicOnError)
flags.IntVar(&Port, "port", Port, "the server port")
flags.StringVarP(&Level, "level", "l", Level, "log level(debug|info|warn|error|panic|fatal)")
flags.StringVarP(&Home, "home", "c", Home, "config home dir")
flags.StringVarP(&Mode, "mode", "m", Mode, "running mode(dev|test|stag|prod|release)")
flags.BoolVarP(&Trace, "trace", "t", Trace, "enable trace")
Expand Down
Loading

0 comments on commit 6b98400

Please sign in to comment.