Skip to content

Commit

Permalink
feat: impl GetServerInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Apr 17, 2023
1 parent d59cce8 commit 771aa2c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ builds:
flags:
- -tags=release
ldflags:
- -s -w -X main.name={{.ProjectName}} -X main.version={{.Summary}}
- -s -w -X main.name={{.ProjectName}} -X main.version={{.Summary}} -X main.date={{.Date}} -X main.protoVersion={{.Env.PROTO_VERSION}}
#buildmode: c-archive

archives:
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ PACKAGE_NAME := github.com/tuihub/librarian
GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
GOLANG_CROSS_VERSION ?= v1.19.6
PROTO_VERSION=$(shell go list -m -f '{{.Version}}' github.com/tuihub/protos)
GOLANG_CROSS_VERSION ?= v1.19.6
SHELL:=/bin/bash

ifeq ($(GOHOSTOS), windows)
Expand Down Expand Up @@ -78,14 +79,15 @@ run:
.PHONY: build
# build server in debug mode
build:
mkdir -p bin/ && go build -tags debug -ldflags "-X main.version=$(VERSION)" -o ./bin/ ./...
mkdir -p bin/ && go build -tags debug -ldflags "-X main.version=$(VERSION) -X main.protoVersion=$(PROTO_VERSION)" -o ./bin/ ./...

.PHONY: release-dry-run
# build server in release mode, for manual test
release-dry-run:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-e PROTO_VERSION=$(PROTO_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
Expand All @@ -106,6 +108,7 @@ release:
docker run \
--rm \
-e CGO_ENABLED=1 \
-e PROTO_VERSION=$(PROTO_VERSION) \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOME)/.docker/config.json:/root/.docker/config.json \
Expand Down
8 changes: 7 additions & 1 deletion app/mapper/cmd/mapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ var (
version string

id, _ = os.Hostname() //nolint:gochecknoglobals //TODO

// date is the build date of the compiled software.
date string //nolint:gochecknoglobals //TODO

// version is the proto version of the compiled software.
protoVersion string //nolint:gochecknoglobals //TODO
)

func newApp(gs *grpc.Server, r registry.Registrar) *kratos.App {
Expand All @@ -33,7 +39,7 @@ func newApp(gs *grpc.Server, r registry.Registrar) *kratos.App {
}

func main() {
appSettings, err := libapp.NewAppSettings(id, name, version)
appSettings, err := libapp.NewAppSettings(id, name, version, protoVersion, date)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion app/porter/cmd/porter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ var (
version string

id, _ = os.Hostname() //nolint:gochecknoglobals //TODO

// date is the build date of the compiled software.
date string //nolint:gochecknoglobals //TODO

// version is the proto version of the compiled software.
protoVersion string //nolint:gochecknoglobals //TODO
)

func newApp(gs *grpc.Server, r registry.Registrar, m metadata) *kratos.App {
Expand All @@ -36,7 +42,7 @@ func newApp(gs *grpc.Server, r registry.Registrar, m metadata) *kratos.App {
}

func main() {
appSettings, err := libapp.NewAppSettings(id, name, version)
appSettings, err := libapp.NewAppSettings(id, name, version, protoVersion, date)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion app/searcher/cmd/searcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ var (
version string

id, _ = os.Hostname() //nolint:gochecknoglobals //TODO

// date is the build date of the compiled software.
date string //nolint:gochecknoglobals //TODO

// version is the proto version of the compiled software.
protoVersion string //nolint:gochecknoglobals //TODO
)

func newApp(gs *grpc.Server, r registry.Registrar) *kratos.App {
Expand All @@ -33,7 +39,7 @@ func newApp(gs *grpc.Server, r registry.Registrar) *kratos.App {
}

func main() {
appSettings, err := libapp.NewAppSettings(id, name, version)
appSettings, err := libapp.NewAppSettings(id, name, version, protoVersion, date)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion app/sephirah/cmd/sephirah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ var (
version string

id, _ = os.Hostname() //nolint:gochecknoglobals //TODO

// date is the build date of the compiled software.
date string //nolint:gochecknoglobals //TODO

// version is the proto version of the compiled software.
protoVersion string //nolint:gochecknoglobals //TODO
)

func newApp(gs *grpc.Server, hs *http.Server, mq *libmq.MQ, cron *libcron.Cron) *kratos.App {
Expand All @@ -34,7 +40,7 @@ func newApp(gs *grpc.Server, hs *http.Server, mq *libmq.MQ, cron *libcron.Cron)
}

func main() {
appSettings, err := libapp.NewAppSettings(id, name, version)
appSettings, err := libapp.NewAppSettings(id, name, version, protoVersion, date)
if err != nil {
panic(err)
}
Expand Down
20 changes: 20 additions & 0 deletions app/sephirah/internal/service/librariansephirahservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"time"

"github.com/tuihub/librarian/app/sephirah/internal/biz/bizangela"
"github.com/tuihub/librarian/app/sephirah/internal/biz/bizbinah"
Expand All @@ -12,6 +13,8 @@ import (
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/internal/lib/libapp"
pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"

"google.golang.org/protobuf/types/known/timestamppb"
)

type LibrarianSephirahServiceService struct {
Expand All @@ -22,6 +25,7 @@ type LibrarianSephirahServiceService struct {
b *bizbinah.Binah
y *bizyesod.Yesod
n *biznetzach.Netzach
app *libapp.Settings
authFunc func(context.Context) (context.Context, error)
}

Expand Down Expand Up @@ -51,6 +55,22 @@ func NewLibrarianSephirahServiceService(
b: b,
y: y,
n: n,
app: app,
authFunc: authFunc,
}
}

func (s *LibrarianSephirahServiceService) GetServerInformation(_ context.Context,
_ *pb.GetServerInformationRequest) (*pb.GetServerInformationResponse, error) {
return &pb.GetServerInformationResponse{
ServerBinarySummary: &pb.ServerBinarySummary{
SourceCodeAddress: s.app.SourceCodeAddress,
BuildVersion: s.app.Version,
BuildDate: s.app.BuildDate,
},
ProtocolSummary: &pb.ServerProtocolSummary{
Version: s.app.ProtoVersion,
},
CurrentTime: timestamppb.New(time.Now()),
}, nil
}
8 changes: 7 additions & 1 deletion cmd/librarian/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ var (
version string

id, _ = os.Hostname() //nolint:gochecknoglobals //TODO

// date is the build date of the compiled software.
date string //nolint:gochecknoglobals //TODO

// version is the proto version of the compiled software.
protoVersion string //nolint:gochecknoglobals //TODO
)

var ProviderSet = wire.NewSet(newApp, mapperClientSelector, searcherClientSelector, porterClientSelector)
Expand All @@ -42,7 +48,7 @@ func newApp(gs *grpc.Server, hs *http.Server, mq *libmq.MQ, cron *libcron.Cron)
}

func main() {
appSettings, err := libapp.NewAppSettings(id, name, version)
appSettings, err := libapp.NewAppSettings(id, name, version, protoVersion, date)
if err != nil {
panic(err)
}
Expand Down
10 changes: 9 additions & 1 deletion internal/lib/libapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type Settings struct {
env config.Config
InherentSettings
Flags
Version string
ProtoVersion string
BuildDate string
SourceCodeAddress string
}

type Flags struct {
Expand All @@ -37,7 +41,7 @@ const (
EnvLogLevel Env = "LOG_LEVEL"
)

func NewAppSettings(id, name, version string) (*Settings, error) {
func NewAppSettings(id, name, version, protoVersion, date string) (*Settings, error) {
var as Settings
flags := loadFlags()
if err := checkDataPath(flags.DataPath); err != nil {
Expand All @@ -51,6 +55,10 @@ func NewAppSettings(id, name, version string) (*Settings, error) {
e,
getInherentSettings(),
flags,
version,
protoVersion,
date,
"https://github.com/TuiHub/Librarian",
}
}
if as.ConfPath == "" {
Expand Down
1 change: 1 addition & 0 deletions internal/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewWhiteListMatcher() selector.MatchFunc {
whiteList := make(map[string]struct{})
whiteList["/grpc.health.v1.Health/Check"] = struct{}{}
whiteList["/grpc.health.v1.Health/Watch"] = struct{}{}
whiteList["/librarian.sephirah.v1.LibrarianSephirahService/GetServerInformation"] = struct{}{}
whiteList["/librarian.sephirah.v1.LibrarianSephirahService/GetToken"] = struct{}{}
whiteList["/librarian.sephirah.v1.LibrarianSephirahService/RefreshToken"] = struct{}{}
return func(ctx context.Context, operation string) bool {
Expand Down

0 comments on commit 771aa2c

Please sign in to comment.