Skip to content

Commit

Permalink
change example (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored May 17, 2024
1 parent 22c9f80 commit 790c6e0
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 124 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

14 changes: 6 additions & 8 deletions examples/grpc/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection/grpc_reflection_v1"

"github.com/nil-go/nilgo"
ngrpc "github.com/nil-go/nilgo/grpc"
"github.com/nil-go/nilgo/run"
)

const endpoint = "unix:.grpc.sock"

func TestMain(m *testing.M) {
server := grpc.NewServer()
runner := run.New(run.WithPreRun(ngrpc.Run(server, ngrpc.WithAddress(endpoint))))
runner := nilgo.New(nilgo.WithPreRun(ngrpc.Run(server, ngrpc.WithAddress(endpoint))))

if err := runner.Run(context.Background(), func(context.Context) error {
if m.Run() != 0 {
Expand All @@ -45,9 +45,8 @@ func TestMain(m *testing.M) {

func TestHealthCheck(t *testing.T) {
ctx := context.Background()
conn, err := grpc.DialContext(
ctx, endpoint,
grpc.WithBlock(),
conn, err := grpc.NewClient(
endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
require.NoError(t, err)
Expand All @@ -63,9 +62,8 @@ func TestHealthCheck(t *testing.T) {

func TestReflection(t *testing.T) {
ctx := context.Background()
conn, err := grpc.DialContext(
ctx, endpoint,
grpc.WithBlock(),
conn, err := grpc.NewClient(
endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
require.NoError(t, err)
Expand Down
33 changes: 21 additions & 12 deletions examples/grpc/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,51 @@
package main

import (
"context"

"cloud.google.com/go/compute/metadata"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"

"github.com/nil-go/nilgo"
"github.com/nil-go/nilgo/dev"
"github.com/nil-go/nilgo/gcp"
"github.com/nil-go/nilgo/gcp/log"
"github.com/nil-go/nilgo/gcp/profiler"
ngrpc "github.com/nil-go/nilgo/grpc"
"github.com/nil-go/nilgo/otlp"
)

func main() {
var args []any
var (
opts []nilgo.Option
runs []func(context.Context) error
)
switch {
case metadata.OnGCE():
opts, err := gcp.Args(
gcp.WithLog(),
gcp.WithTrace(),
gcp.WithMetric(),
gcp.WithProfiler(profiler.WithMutexProfiling()),
)
opts = append(opts, nilgo.WithLogger(log.Logger()))
traceProvider, err := otlp.TraceProvider()
if err != nil {
panic(err)
}
opts = append(opts, nilgo.WithTraceProvider(traceProvider))
meterProvider, err := otlp.MeterProvider()
if err != nil {
panic(err)
}
args = append(args, opts...)
opts = append(opts, nilgo.WithMeterProvider(meterProvider))
runs = append(runs, profiler.Run(profiler.WithMutexProfiling()))
default:
args = append(args, dev.Pprof)
runs = append(runs, dev.Pprof)
}
args = append(args,

runs = append(runs,
ngrpc.Run(
ngrpc.NewServer(grpc.StatsHandler(otelgrpc.NewServerHandler())),
ngrpc.WithConfigService(),
),
)

if err := nilgo.Run(args...); err != nil {
if err := nilgo.New(opts...).Run(context.Background(), runs...); err != nil {
panic(err)
}
}
25 changes: 13 additions & 12 deletions examples/grpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ go 1.21

require (
cloud.google.com/go/compute/metadata v0.3.0
github.com/nil-go/nilgo v0.1.0
github.com/nil-go/nilgo/gcp v0.1.0
github.com/nil-go/nilgo/grpc v0.1.0
github.com/nil-go/nilgo v0.2.0
github.com/nil-go/nilgo/gcp v0.2.0
github.com/nil-go/nilgo/grpc v0.2.0
github.com/nil-go/nilgo/otlp v0.2.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0
go.uber.org/goleak v1.3.0
google.golang.org/grpc v1.63.2
google.golang.org/grpc v1.64.0
)

require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go v0.113.0 // indirect
cloud.google.com/go/auth v0.4.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/profiler v0.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand All @@ -24,11 +25,11 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e // indirect
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/nil-go/konf v1.1.1 // indirect
github.com/nil-go/sloth v0.3.0 // indirect
github.com/nil-go/sloth/otel v0.3.0 // indirect
Expand All @@ -50,10 +51,10 @@ require (
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.177.0 // indirect
google.golang.org/genproto v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/api v0.181.0 // indirect
google.golang.org/genproto v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
58 changes: 30 additions & 28 deletions examples/grpc/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.112.2 h1:ZaGT6LiG7dBzi6zNOvVZwacaXlmf3lRqnC4DQzqyRQw=
cloud.google.com/go v0.112.2/go.mod h1:iEqjp//KquGIJV/m+Pk3xecgKNhV+ry+vVTsy4TbDms=
cloud.google.com/go/auth v0.3.0 h1:PRyzEpGfx/Z9e8+lHsbkoUVXD0gnu4MNmm7Gp8TQNIs=
cloud.google.com/go/auth v0.3.0/go.mod h1:lBv6NKTWp8E3LPzmO1TbiiRKc4drLOfHsgmlH9ogv5w=
cloud.google.com/go v0.113.0 h1:g3C70mn3lWfckKBiCVsAshabrDg01pQ0pnX1MNtnMkA=
cloud.google.com/go v0.113.0/go.mod h1:glEqlogERKYeePz6ZdkcLJ28Q2I6aERgDDErBg9GzO8=
cloud.google.com/go/auth v0.4.1 h1:Z7YNIhlWRtrnKlZke7z3GMqzvuYzdc2z98F9D1NV5Hg=
cloud.google.com/go/auth v0.4.1/go.mod h1:QVBuVEKpCn4Zp58hzRGvL0tjRGU0YqdRTdCHM1IHnro=
cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4=
cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q=
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
Expand All @@ -11,16 +11,16 @@ cloud.google.com/go/iam v1.1.8 h1:r7umDwhj+BQyz0ScZMp4QrGXjSTI3ZINnpgU2nlB/K0=
cloud.google.com/go/iam v1.1.8/go.mod h1:GvE6lyMmfxXauzNq8NbgJbeVQNspG+tcdL/W8QO1+zE=
cloud.google.com/go/profiler v0.4.0 h1:ZeRDZbsOBDyRG0OiK0Op1/XWZ3xeLwJc9zjkzczUxyY=
cloud.google.com/go/profiler v0.4.0/go.mod h1:RvPlm4dilIr3oJtAOeFQU9Lrt5RoySHSDj4pTd6TWeU=
cloud.google.com/go/storage v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY=
cloud.google.com/go/storage v1.39.1/go.mod h1:xK6xZmxZmo+fyP7+DEF6FhNc24/JAe95OLyOHCXFH1o=
cloud.google.com/go/storage v1.40.0 h1:VEpDQV5CJxFmJ6ueWNsKxcr1QAYOXEgxDa+sBbJahPw=
cloud.google.com/go/storage v1.40.0/go.mod h1:Rrj7/hKlG87BLqDJYtwR0fbPld8uJPbQ2ucUMY7Ir0g=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ=
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc=
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -63,8 +63,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e h1:RsXNnXE59RTt8o3DcA+w7ICdRfR2l+Bb5aE0YMpNTO8=
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 h1:velgFPYr1X9TDwLIfkV7fWqsFlf7TeP11M/7kPd/dVI=
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -74,20 +74,22 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
github.com/googleapis/gax-go/v2 v2.12.4 h1:9gWcmF85Wvq4ryPFvGFaOgPIs1AQX0d0bcbGw4Z96qg=
github.com/googleapis/gax-go/v2 v2.12.4/go.mod h1:KYEYLorsnIGDi/rPC8b5TdlB9kbKoFubselGIoBMCwI=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nil-go/konf v1.1.1 h1:7c381m9P3M/VBzv7vqZ3UyXilMa5oJN9BBffuX6Ooy8=
github.com/nil-go/konf v1.1.1/go.mod h1:ULW6PmJzWMd0F4KKNJQPhWD6Zu5eoX9U1C9SW2BPAr4=
github.com/nil-go/nilgo v0.1.0 h1:nEsB+K8xC8GkgRYrUSSv+2MEnFjDXXGkH+MK6cGoX/Q=
github.com/nil-go/nilgo v0.1.0/go.mod h1:POkJibC6ANp5qz+QNDZy6Dw9GfPWDNRyXD/85G5ElSs=
github.com/nil-go/nilgo/gcp v0.1.0 h1:3a7HkgrFABxa1S3yH4OYscjTz3C1ES/yRARapzbMXks=
github.com/nil-go/nilgo/gcp v0.1.0/go.mod h1:jBI0WjpxAvBmioj6nFKYSZ/+F70ImQHov5HpOs1on4I=
github.com/nil-go/nilgo/grpc v0.1.0 h1:eJH6CoZOGnfw+q03hskeB2aG7KGyBPLDVZ4Uv+kZFmg=
github.com/nil-go/nilgo/grpc v0.1.0/go.mod h1:rGnKj384LJ686RRmvNOmmdC6WuRXyw4ZZ9Rg7duMSvg=
github.com/nil-go/nilgo v0.2.0 h1:zmiPm5XeJTAX0S6gRCM0TuGV4rmneovsK4hKOQc0jA4=
github.com/nil-go/nilgo v0.2.0/go.mod h1:3E1DXM7/T6SlA1zKpj5bhRx0lfb1i37JZeO2hw1Vt7k=
github.com/nil-go/nilgo/gcp v0.2.0 h1:WCtkDQyT1fsFEP8DzX3eN5oLgjcnx6OKYs9MgrIYi2s=
github.com/nil-go/nilgo/gcp v0.2.0/go.mod h1:b9MnXdKcv1pzyvzerg07cgHjRufTRXRnzPmBY9eUvPk=
github.com/nil-go/nilgo/grpc v0.2.0 h1:yvzKnoL2Uib97+6JZXNS7LPTrqlysuT5hWNClWSvl9s=
github.com/nil-go/nilgo/grpc v0.2.0/go.mod h1:YMFcmhtEDDe9gtlTbpN/q37BK4N2/W8Sbffx0Vr4dFc=
github.com/nil-go/nilgo/otlp v0.2.0 h1:Wc5+/bWCSh/Q9zt1NPbT8QmEWj07V+p8dF3PwTqY4rQ=
github.com/nil-go/nilgo/otlp v0.2.0/go.mod h1:9lzMydme2AjzcTguEwXRUKe5t4BlcdEe4+X44A0uwA8=
github.com/nil-go/sloth v0.3.0 h1:lAqd8/pH6psoXZDpScCefY+3V9PVfJnIyOqMK1GSvwo=
github.com/nil-go/sloth v0.3.0/go.mod h1:SE8dLU9DLYeuLtu3kHp9PUEyj0OwUGKvTjSpx8tPdwo=
github.com/nil-go/sloth/otel v0.3.0 h1:BCF2oExOkzDjky8IHkT/4CqKvimbQldWp650qNk+vBo=
Expand Down Expand Up @@ -173,26 +175,26 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.177.0 h1:8a0p/BbPa65GlqGWtUKxot4p0TV8OGOfyTjtmkXNXmk=
google.golang.org/api v0.177.0/go.mod h1:srbhue4MLjkjbkux5p3dw/ocYOSZTaIEvf7bCOnFQDw=
google.golang.org/api v0.181.0 h1:rPdjwnWgiPPOJx3IcSAQ2III5aX5tCer6wMpa/xmZi4=
google.golang.org/api v0.181.0/go.mod h1:MnQ+M0CFsfUwA5beZ+g/vCBCPXvtmZwRz2qzZk8ih1k=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240506185236-b8a5c65736ae h1:HjgkYCl6cWQEKSHkpUp4Q8VB74swzyBwTz1wtTzahm0=
google.golang.org/genproto v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:i4np6Wrjp8EujFAUn0CM0SH+iZhY1EbrfzEIJbFkHFM=
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae h1:AH34z6WAGVNkllnKs5raNq3yRq93VnjBG6rpfub/jYk=
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:FfiGhwUm6CJviekPrc0oJ+7h29e+DmWU6UtjX0ZvI7Y=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae h1:c55+MER4zkBS14uJhSZMGGmya0yJx5iHV4x/fpOSNRk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/genproto v0.0.0-20240515191416-fc5f0ca64291 h1:CTZGpOdDJr2Jq+LcJ/mpjG8mClGy/uJdBBVYbS9g5lY=
google.golang.org/genproto v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:ch5ZrEj5+9MCxUeR3Gp3mCJ4u0eVpusYAmSr/mvpMSk=
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291 h1:4HZJ3Xv1cmrJ+0aFo304Zn79ur1HMxptAE7aCPNLSqc=
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
32 changes: 20 additions & 12 deletions examples/http/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"context"
"log/slog"
"net/http"
"time"
Expand All @@ -13,26 +14,33 @@ import (

"github.com/nil-go/nilgo"
"github.com/nil-go/nilgo/dev"
"github.com/nil-go/nilgo/gcp"
"github.com/nil-go/nilgo/gcp/log"
"github.com/nil-go/nilgo/gcp/profiler"
nhttp "github.com/nil-go/nilgo/http"
"github.com/nil-go/nilgo/otlp"
)

func main() {
var args []any
var (
opts []nilgo.Option
runs []func(context.Context) error
)
switch {
case metadata.OnGCE():
opts, err := gcp.Args(
gcp.WithLog(),
gcp.WithTrace(),
gcp.WithMetric(),
gcp.WithProfiler(),
)
opts = append(opts, nilgo.WithLogger(log.Logger()))
traceProvider, err := otlp.TraceProvider()
if err != nil {
panic(err)
}
opts = append(opts, nilgo.WithTraceProvider(traceProvider))
meterProvider, err := otlp.MeterProvider()
if err != nil {
panic(err)
}
args = append(args, opts...)
opts = append(opts, nilgo.WithMeterProvider(meterProvider))
runs = append(runs, profiler.Run(profiler.WithMutexProfiling()))
default:
args = append(args, dev.Pprof)
runs = append(runs, dev.Pprof)
}

mux := http.NewServeMux()
Expand All @@ -57,11 +65,11 @@ func main() {
})),
ReadTimeout: time.Second,
}
args = append(args,
runs = append(runs,
nhttp.Run(server, nhttp.WithConfigService()),
)

if err := nilgo.Run(args...); err != nil {
if err := nilgo.New(opts...).Run(context.Background(), runs...); err != nil {
panic(err)
}
}
26 changes: 13 additions & 13 deletions examples/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ go 1.22

require (
cloud.google.com/go/compute/metadata v0.3.0
github.com/nil-go/nilgo v0.1.0
github.com/nil-go/nilgo/gcp v0.1.0
github.com/nil-go/nilgo/http v0.1.0
github.com/nil-go/nilgo v0.2.0
github.com/nil-go/nilgo/gcp v0.2.0
github.com/nil-go/nilgo/http v0.2.0
github.com/nil-go/nilgo/otlp v0.2.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0
)

require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go v0.113.0 // indirect
cloud.google.com/go/auth v0.4.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/profiler v0.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand All @@ -21,11 +22,11 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e // indirect
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/nil-go/konf v1.1.1 // indirect
github.com/nil-go/sloth v0.3.0 // indirect
github.com/nil-go/sloth/otel v0.3.0 // indirect
Expand All @@ -47,11 +48,10 @@ require (
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.177.0 // indirect
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/api v0.181.0 // indirect
google.golang.org/genproto v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 790c6e0

Please sign in to comment.