generated from danthegoodman1/GoAPITemplate
-
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
0 parents
commit 7633795
Showing
32 changed files
with
4,043 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
.idea |
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,32 @@ | ||
FROM golang:1.21.1-bullseye as build | ||
|
||
WORKDIR /app | ||
|
||
# START GIT PRIVATE SECTION - delete if not using private packages | ||
ARG GIT_INSTEAD_OF=ssh://[email protected]/ | ||
ARG GO_ARGS="" | ||
|
||
# Need ssh for private packages | ||
RUN mkdir /root/.ssh && echo "# github.com\n|1|ljja8g3oSggsnjO9rsrgs7Udx2s=|I6pPqynzf/0nwAnJ3LQ4n9n6Gc8= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=\n|1|rFMG6UlqGl4xrNGGKf6FYK56sMU=|bLF794kw2BGoKCjiN696DX+dMh4= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=" >> /root/.ssh/known_hosts | ||
RUN go env -w GOPRIVATE=github.com/<YOUR ORG> | ||
RUN git config --global url."${GIT_INSTEAD_OF}".insteadOf https://github.com/ | ||
# END GIT PRIVATE SECTION | ||
|
||
COPY go.* /app/ | ||
|
||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=ssh \ | ||
go mod download | ||
|
||
COPY . . | ||
|
||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
go build $GO_ARGS -o /app/outbin | ||
|
||
# Need glibc | ||
FROM gcr.io/distroless/base-debian11 | ||
|
||
ENTRYPOINT ["/app/outbin"] | ||
COPY --from=build /app/outbin /app/ |
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,15 @@ | ||
# GoAPITemplate | ||
|
||
## Log Context | ||
|
||
The thing that gives logging a separate context is the function call: | ||
|
||
```go | ||
logger := gologger.NewLogger() | ||
// ... | ||
ctx = logger.WithContext(ctx) | ||
``` | ||
|
||
Otherwise all logging will share the context (weird I know). | ||
|
||
From here you can use `logger := zerolog.Ctx(ctx)` |
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,68 @@ | ||
version: '3' | ||
|
||
dotenv: ['.env'] | ||
|
||
vars: | ||
sql_migrate_version: v1.5.2 | ||
sql_c_version: v1.19.1 | ||
|
||
env: | ||
DOCKER_BUILDKIT: "1" | ||
|
||
tasks: | ||
default: | ||
- go run . | ||
|
||
single-test: | ||
cmds: | ||
- go test --count=1 -v {{.CLI_ARGS}} | ||
# task single-test -- ./emailing -run TestSendEmail | ||
# - go test --count=1 -v ./... -run {{.CLI_ARGS}} | ||
# task single-test -- TestName | ||
|
||
install-deps: | ||
cmds: | ||
- go install github.com/rubenv/sql-migrate/...@{{.sql_migrate_version}} | ||
- go install github.com/kyleconroy/sqlc/cmd/sqlc@{{.sql_c_version}} | ||
|
||
sql-up: | ||
preconditions: | ||
- msg: set env CRDB_DSN and SQL_ENV to local,staging,prod,development | ||
sh: echo $SQL_ENV | grep . | ||
cmds: | ||
- sql-migrate up --env=$SQL_ENV | ||
- task: sql-status | ||
|
||
sql-down: | ||
preconditions: | ||
- msg: set env CRDB_DSN and SQL_ENV to local,staging,prod,development | ||
sh: echo $SQL_ENV | grep . | ||
cmds: | ||
- sql-migrate down --env=$SQL_ENV | ||
- task: sql-status | ||
|
||
sql-status: | ||
preconditions: | ||
- msg: set env CRDB_DSN and SQL_ENV to local,staging,prod,development | ||
sh: echo $SQL_ENV | grep . | ||
cmds: | ||
- sql-migrate status --env=$SQL_ENV | ||
|
||
sql-gen: | ||
desc: generate typed methods for SQL execution | ||
silent: true | ||
cmds: | ||
# concatenates all migrations but drops the "migrate down" parts | ||
- ls migrations/*.sql migrations/*.sql.later | xargs -n1 sed '/^-- +migrate Down/ ,$d' > schema.sql | ||
# There are a bunch of SQL features that don't matter for SQLC but break their parser | ||
- sed -i -e 's/ON UPDATE NOW[(][)]//g' schema.sql | ||
- sed -i -e 's/CREATE DATABASE.*//g' schema.sql | ||
- sed -i -e 's/CREATE INDEX.*//g' schema.sql | ||
- sed -i -e 's/CREATE USER.*//g' schema.sql | ||
- sed -i -e 's/GRANT.*//g' schema.sql | ||
- sed -i -e 's/DESC//g' schema.sql | ||
- sed -i -e 's/USING HASH.*//g' schema.sql | ||
- rm -f query/*.sql.go | ||
- sqlc generate | ||
- rm schema.sql* | ||
- echo done |
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,39 @@ | ||
package crdb | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/danthegoodman1/GoAPITemplate/gologger" | ||
"github.com/danthegoodman1/GoAPITemplate/utils" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
) | ||
|
||
var ( | ||
PGPool *pgxpool.Pool | ||
StandardContextTimeout = 10 * time.Second | ||
|
||
logger = gologger.NewLogger() | ||
) | ||
|
||
func ConnectToDB() error { | ||
logger.Debug().Msg("connecting to CRDB...") | ||
var err error | ||
config, err := pgxpool.ParseConfig(utils.CRDB_DSN) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
config.MaxConns = 10 | ||
config.MinConns = 1 | ||
config.HealthCheckPeriod = time.Second * 5 | ||
config.MaxConnLifetime = time.Minute * 30 | ||
config.MaxConnIdleTime = time.Minute * 30 | ||
|
||
PGPool, err = pgxpool.NewWithConfig(context.Background(), config) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Debug().Msg("connected to CRDB") | ||
return nil | ||
} |
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,23 @@ | ||
local: | ||
dialect: postgres | ||
datasource: dbname=defaultdb sslmode=disable host=localhost port=26257 user=root | ||
dir: migrations | ||
table: migrations | ||
|
||
staging: | ||
dialect: postgres | ||
datasource: dbname=tangia sslmode=require host=blah port=26257 user=${CRDB_USER} password=${CRDB_PASSWORD} sslrootcert=staging.crt | ||
dir: migrations | ||
table: migrations | ||
|
||
development: | ||
dialect: postgres | ||
datasource: dbname=tangia sslmode=require host=blah port=26257 user=${CRDB_USER} password=${CRDB_PASSWORD} sslrootcert=staging.crt | ||
dir: migrations | ||
table: migrations | ||
|
||
prod: | ||
dialect: postgres | ||
datasource: ${CRDB_DSN} | ||
dir: migrations | ||
table: migrations |
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,90 @@ | ||
module github.com/danthegoodman1/GoAPITemplate | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/UltimateTournament/backoff/v4 v4.2.1 | ||
github.com/cockroachdb/cockroach-go/v2 v2.3.5 | ||
github.com/go-playground/validator/v10 v10.11.1 | ||
github.com/google/uuid v1.3.1 | ||
github.com/jackc/pgtype v1.12.0 | ||
github.com/jackc/pgx/v5 v5.4.3 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/labstack/echo/v4 v4.11.1 | ||
github.com/matoous/go-nanoid/v2 v2.0.0 | ||
github.com/prometheus/client_golang v1.16.0 | ||
github.com/rs/zerolog v1.29.1 | ||
github.com/rubenv/sql-migrate v1.2.0 | ||
github.com/samber/lo v1.38.1 | ||
github.com/segmentio/ksuid v1.0.4 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/uber-go/tally/v4 v4.1.7 | ||
go.opentelemetry.io/otel v1.21.0 | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 | ||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 | ||
go.opentelemetry.io/otel/sdk v1.21.0 | ||
go.opentelemetry.io/otel/trace v1.21.0 | ||
go.temporal.io/api v1.21.0 | ||
go.temporal.io/sdk v1.23.1 | ||
go.temporal.io/sdk/contrib/opentelemetry v0.2.0 | ||
go.temporal.io/sdk/contrib/tally v0.2.0 | ||
golang.org/x/net v0.17.0 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect | ||
github.com/go-gorp/gorp/v3 v3.0.2 // indirect | ||
github.com/go-logr/logr v1.3.0 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-playground/locales v0.14.0 // indirect | ||
github.com/go-playground/universal-translator v0.18.0 // indirect | ||
github.com/gogo/googleapis v1.4.1 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/gogo/status v1.1.1 // indirect | ||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect | ||
github.com/golang/mock v1.6.0 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect | ||
github.com/jackc/pgio v1.0.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgproto3/v2 v2.3.1 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
github.com/jackc/puddle/v2 v2.2.1 // indirect | ||
github.com/labstack/gommon v0.4.0 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/pborman/uuid v1.2.1 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/prometheus/client_model v0.3.0 // indirect | ||
github.com/prometheus/common v0.42.0 // indirect | ||
github.com/prometheus/procfs v0.10.1 // indirect | ||
github.com/robfig/cron v1.2.0 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/twmb/murmur3 v1.1.5 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasttemplate v1.2.2 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.21.0 // indirect | ||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect | ||
go.uber.org/atomic v1.10.0 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect | ||
golang.org/x/sync v0.3.0 // indirect | ||
golang.org/x/sys v0.14.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect | ||
google.golang.org/grpc v1.59.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.