forked from pathwar/pathwar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
526 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
vendor/ | ||
*~ | ||
*# | ||
.#* | ||
|
||
/.generated | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
## | ||
## functions | ||
## | ||
|
||
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) | ||
|
||
## | ||
## vars | ||
## | ||
|
||
GOPATH ?= $(HOME)/go | ||
BIN = $(GOPATH)/bin/pathwar.pw | ||
SOURCES = $(call rwildcard, ./, *.go) | ||
PROTOS = $(call rwildcard, ./, *.proto) | ||
GENERATED_FILES = \ | ||
$(patsubst %.proto,%.pb.go,$(PROTOS)) \ | ||
$(call rwildcard ./, *.gen.go) | ||
PROTOC_OPTS = -I/protobuf:. | ||
RUN_OPTS ?= | ||
|
||
## | ||
## rules | ||
## | ||
|
||
.PHONY: help | ||
help: | ||
@echo "Make commands:" | ||
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: \ | ||
'/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | \ | ||
sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | grep -v / | \ | ||
sed 's/^/ $(HELP_MSG_PREFIX)make /' | ||
|
||
.PHONY: run | ||
run: $(BIN) | ||
$(BIN) server $(RUN_OPTS) | ||
|
||
.PHONY: install | ||
install: $(BIN) | ||
$(BIN): .generated $(SOURCES) | ||
go install -v | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(GENERATED_FILES) .generated | ||
|
||
.PHONY: generate | ||
generate: .generated | ||
.generated: $(PROTOS) | ||
rm -f $(GENERATED_FILES) | ||
docker run \ | ||
--user="$(shell id -u)" \ | ||
--volume="$(PWD):/go/src/pathwar.pw" \ | ||
--workdir="/go/src/pathwar.pw" \ | ||
--entrypoint="sh" \ | ||
--rm \ | ||
moul/protoc-gen-gotemplate \ | ||
-xec "make _generate" | ||
touch $@ | ||
|
||
.PHONY: _generate | ||
_generate: $(GENERATED_FILES) | ||
|
||
%.pb.go: %.proto | ||
protoc $(PROTOC_OPTS) --gofast_out=plugins=grpc:"$(GOPATH)/src" "$(dir $<)"/*.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
module pathwar.pw | ||
|
||
require ( | ||
github.com/golang/protobuf v1.2.0 | ||
github.com/pkg/errors v0.8.0 | ||
github.com/spf13/cobra v0.0.3 | ||
github.com/spf13/pflag v1.0.3 | ||
github.com/spf13/viper v1.2.1 | ||
go.uber.org/atomic v1.3.2 // indirect | ||
go.uber.org/multierr v1.1.0 // indirect | ||
go.uber.org/zap v1.9.1 | ||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a | ||
google.golang.org/grpc v1.16.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"net" | ||
|
||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type serverOptions struct { | ||
GRPCBind string | ||
} | ||
|
||
func (opts serverOptions) String() string { | ||
out, _ := json.Marshal(opts) | ||
return string(out) | ||
} | ||
|
||
func server(opts *serverOptions) error { | ||
listener, err := net.Listen("tcp", opts.GRPCBind) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to listen") | ||
} | ||
|
||
grpcServer := grpc.NewServer() | ||
RegisterServerServer(grpcServer, &svc{}) | ||
|
||
zap.L().Info("grpc server started", zap.String("bind", opts.GRPCBind)) | ||
grpcServer.Serve(listener) | ||
return nil | ||
} |
Oops, something went wrong.