rename, add Makefile rename support
This commit is contained in:
parent
95aa1e47d1
commit
c8e461729f
23
Makefile
23
Makefile
@ -7,7 +7,7 @@ PROTO_DIRS := $(wildcard proto/demo/app/*) # TODO: Update path (probably not dem
|
||||
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
|
||||
OUTPUT_DIR := bin
|
||||
VER_PKG := gitea.libretechconsulting.com/rmcguire/go-app/pkg/config.Version
|
||||
DOCKER_IMG := gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel
|
||||
GIT_REPO := gitea.libretechconsulting.com/rmcguire/go-server-with-otel
|
||||
|
||||
all: proto test build docker
|
||||
|
||||
@ -37,12 +37,12 @@ schema:
|
||||
go run . -schema > contrib/schema.json
|
||||
|
||||
docker:
|
||||
@echo "Building Docker image $(DOCKER_IMG):$(VERSION)"
|
||||
@echo "Building Docker image $(GIT_REPO):$(VERSION)"
|
||||
docker build \
|
||||
--build-arg VER_PKG=$(VER_PKG) \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
-t $(DOCKER_IMG):$(VERSION) .
|
||||
docker push $(DOCKER_IMG):$(VERSION)
|
||||
-t $(GIT_REPO):$(VERSION) .
|
||||
docker push $(GIT_REPO):$(VERSION)
|
||||
|
||||
install:
|
||||
go install -v -ldflags "-X $(VER_PKG)=$(VERSION)" .
|
||||
@ -59,3 +59,18 @@ check_protoc:
|
||||
echo "Error: protoc-gen-go-grpc not found in PATH"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
rename:
|
||||
@echo "Current module path: $(GIT_REPO)"
|
||||
@echo "Usage: make rename NAME=your/new/module/name"
|
||||
@if [ -z "$(NAME)" ]; then \
|
||||
echo "No name provided. Aborting."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@echo "New name: $(NAME)"
|
||||
@echo "Are you sure you want to proceed? (y/N): " && read CONFIRM && if [ "$$CONFIRM" != "y" ] && [ "$$CONFIRM" != "Y" ]; then \
|
||||
echo "Aborted."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@find . -type f \( -name '*.go' -o -name 'go.mod' -o -name 'go.sum' -o -name '*.proto' -o -name 'Makefile' \) -exec sed -i "s|$(GIT_REPO)|$(NAME)|g" {} +
|
||||
@echo "Project renamed to $(NAME)"
|
||||
|
21
README.md
21
README.md
@ -1,3 +1,20 @@
|
||||
# go-http-server-with-otel
|
||||
# go-server-with-otel
|
||||
|
||||
Template for a go http server with OTEL support
|
||||
Template for a go HTTP + GRPC server with OTEL support. Uses the go-app
|
||||
framework to easily bootstrap a new app with all the bells and whistles.
|
||||
|
||||
The provided proto returns a random fact, and serves only as a reference.
|
||||
It has support for grpc-gateway, and produces an openapi2/swagger spec for
|
||||
use with postman, etc..
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Rename your package using `make rename NAME=my.gitremote.com/pathto/repo`
|
||||
1. Review the config struct, adding any app-specific configuration
|
||||
1. This will be merged with the go-app config, giving logging/http/grpc
|
||||
configuration for free
|
||||
1. Generate a new json schema, for use with your config.yaml: `make schema`
|
||||
1. Ensure you have yaml+json tags
|
||||
1. The yaml-language-server lsp plugin for your favorite editor should
|
||||
pull in the schema using the comment in `config.yaml`
|
||||
1. Implement your things
|
||||
|
@ -153,7 +153,7 @@ const file_demo_app_v1alpha1_app_proto_rawDesc = "" +
|
||||
"\x06source\x18\x03 \x01(\tR\x06source\x12\x1a\n" +
|
||||
"\blanguage\x18\x04 \x01(\tR\blanguage2z\n" +
|
||||
"\x0eDemoAppService\x12h\n" +
|
||||
"\aGetDemo\x12!.demo.app.v1alpha1.GetDemoRequest\x1a\".demo.app.v1alpha1.GetDemoResponse\"\x16\x82\xd3\xe4\x93\x02\x10\x12\x0e/v1alpha1/demoBSZQgitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/api/v1alpha1/demob\x06proto3"
|
||||
"\aGetDemo\x12!.demo.app.v1alpha1.GetDemoRequest\x1a\".demo.app.v1alpha1.GetDemoResponse\"\x16\x82\xd3\xe4\x93\x02\x10\x12\x0e/v1alpha1/demoBSZQgitea.libretechconsulting.com/rmcguire/go-server-with-otel/api/v1alpha1/demob\x06proto3"
|
||||
|
||||
var (
|
||||
file_demo_app_v1alpha1_app_proto_rawDescOnce sync.Once
|
||||
|
@ -1,5 +1,5 @@
|
||||
# App Config
|
||||
APP_NAME="go-http-server-with-otel"
|
||||
APP_NAME="go-server-with-otel"
|
||||
APP_LOG_LEVEL=trace ## For testing only
|
||||
APP_LOG_FORMAT=console ## console, json
|
||||
APP_LOG_TIME_FORMAT=long ## long, short, unix, rfc3339, off
|
||||
@ -10,5 +10,5 @@ APP_OTEL_METRIC_INTERVAL_SECS=15
|
||||
|
||||
# OTEL SDK Config
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT="otel-collector.otel.svc.cluster.local" # Set to your otel collector
|
||||
OTEL_SERVICE_NAME="go-http-server-with-otel"
|
||||
OTEL_SERVICE_NAME="go-server-with-otel"
|
||||
OTEL_RESOURCE_ATTRIBUTES="env=development,service.version=(devel)"
|
||||
|
7
go.mod
7
go.mod
@ -1,4 +1,4 @@
|
||||
module gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel
|
||||
module gitea.libretechconsulting.com/rmcguire/go-server-with-otel
|
||||
|
||||
go 1.24.1
|
||||
|
||||
@ -7,11 +7,11 @@ require (
|
||||
github.com/go-resty/resty/v2 v2.16.5
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3
|
||||
github.com/rs/zerolog v1.34.0
|
||||
go.opentelemetry.io/otel/trace v1.35.0
|
||||
golang.org/x/sys v0.31.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463
|
||||
google.golang.org/grpc v1.71.0
|
||||
google.golang.org/protobuf v1.36.6
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
|
||||
)
|
||||
|
||||
require (
|
||||
@ -23,7 +23,7 @@ require (
|
||||
github.com/swaggest/refl v1.3.1 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
|
||||
go.opentelemetry.io/otel v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel v1.35.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.57.0 // indirect
|
||||
@ -51,7 +51,6 @@ require (
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.35.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||
golang.org/x/net v0.38.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
|
7
go.sum
7
go.sum
@ -1,5 +1,3 @@
|
||||
gitea.libretechconsulting.com/rmcguire/go-app v0.9.1 h1:QihWX1YeCqttpAjXq6nHWvNk1MpIhuW8bSO3G+fbsRg=
|
||||
gitea.libretechconsulting.com/rmcguire/go-app v0.9.1/go.mod h1:W6YHFSGf4nJrgs9DqEaw+3J6ufIARsr1zpOs/V6gRTQ=
|
||||
gitea.libretechconsulting.com/rmcguire/go-app v0.9.2 h1:DTbGae0TR7O+kKI1ZE8txgFnGb0vsYX/urFUFuoZfQM=
|
||||
gitea.libretechconsulting.com/rmcguire/go-app v0.9.2/go.mod h1:W6YHFSGf4nJrgs9DqEaw+3J6ufIARsr1zpOs/V6gRTQ=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
@ -35,7 +33,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1 h1:KcFzXwzM/kGhIRHvc8jdixfIJjVzuUJdnv+5xsPutog=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1/go.mod h1:qOchhhIlmRcqk/O9uCo/puJlyo07YINaIqdZfZG3Jkc=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
|
||||
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
|
||||
@ -128,6 +125,8 @@ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463/go.mod h1:U90ffi8eUL9MwPcrJylN5+Mk2v3vuPDptd5yyNUiRR8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g=
|
||||
@ -141,5 +140,3 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e h1:KqK5c/ghOm8xkHYhlodbp6i6+r+ChV2vuAuVRdFbLro=
|
||||
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||
|
6
main.go
6
main.go
@ -23,9 +23,9 @@ import (
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
||||
optshttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/demogrpc"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/demohttp"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/demogrpc"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/demohttp"
|
||||
)
|
||||
|
||||
var flagSchema bool
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
|
||||
pb "gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/api/demo/app/v1alpha1"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
|
||||
pb "gitea.libretechconsulting.com/rmcguire/go-server-with-otel/api/demo/app/v1alpha1"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/config"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -3,7 +3,7 @@ package demogrpc
|
||||
import (
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
pb "gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/api/demo/app/v1alpha1"
|
||||
pb "gitea.libretechconsulting.com/rmcguire/go-server-with-otel/api/demo/app/v1alpha1"
|
||||
)
|
||||
|
||||
type RandomFact struct {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
demoAppPb "gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/api/demo/app/v1alpha1"
|
||||
demoAppPb "gitea.libretechconsulting.com/rmcguire/go-server-with-otel/api/demo/app/v1alpha1"
|
||||
)
|
||||
|
||||
func (ds *DemoGRPCServer) GetDialOpts() []grpc.DialOption {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/config"
|
||||
)
|
||||
|
||||
type DemoHTTPServer struct {
|
||||
|
@ -4,7 +4,7 @@ package demo.app.v1alpha1;
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
option go_package = "gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/api/v1alpha1/demo";
|
||||
option go_package = "gitea.libretechconsulting.com/rmcguire/go-server-with-otel/api/v1alpha1/demo";
|
||||
|
||||
// Options for random fact, in this case
|
||||
// just a language
|
||||
|
Loading…
x
Reference in New Issue
Block a user