Skip to content

Initial Backend #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Contributing

1. Install go (on arch: `pacman -S go`)
2. In the root directory of the repo, run `podman compose up -d`
3. Obtain [golang migrate](https://github.com/golang-migrate/migrate). You may need to download the CLI directly from a release
4. In `backend`, run `migrate -source file://$(pwd)/migrations -database postgres://postgres:test@localhost:5432/postgres?sslmode=disable up`
5. In `backend`, run `go run .`

### Adding new dependencies
`go mod tidy`

### Formatting
`gofmt -w -s .`

### Creating new DB migrations
Create a new file with an incremented prefix number, a human readable string, and ending with `.up.sql`, with a corresponding `.down.sql` that has the same number prefix to revert your change. Apply these with golang-migrate
4 changes: 4 additions & 0 deletions backend/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tracing:
enabled: false
environment: "local"
version: "local-dev"
23 changes: 23 additions & 0 deletions backend/config/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config

import (
"context"

"github.com/spf13/viper"
)

type configContextKey string

const contextKey configContextKey = "config"

func ContextWithConfig(ctx context.Context, config *viper.Viper) context.Context {
return context.WithValue(ctx, contextKey, config)
}

func FromContext(ctx context.Context) *viper.Viper {
v := ctx.Value(contextKey)
if v == nil {
panic("config not available in context, somewhere it got lost")
}
return v.(*viper.Viper)
}
48 changes: 48 additions & 0 deletions backend/config/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package config

import (
"context"
"fmt"
"sync"

"github.com/spf13/viper"
)

var once sync.Once

/*
* GetConfig determines what config file to look at based on the environment, and constructs a config to use
*/
func GetConfig(_ context.Context) *viper.Viper {
config := viper.New()
config.SetEnvPrefix("cluesheet")

config.BindEnv("config_path")
config.BindEnv("environment")
config.SetDefault("environment", "local")

if config.IsSet("config_path") {
config.SetConfigFile(config.GetString("config_path"))
} else {
config.SetConfigType("yaml")
config.AddConfigPath(".")
config.AddConfigPath("/opt/cluesheet")

switch config.GetString("environment") {
case "local":
config.SetConfigName("config.yaml")
case "develop":
config.SetConfigName("config.dev")
case "prod":
config.SetConfigName("config.prod")
default:
panic(fmt.Sprintf("unknown environment '%s', can't look for config", config.GetString("environment")))
}
}
err := config.ReadInConfig()
if err != nil {
panic(fmt.Sprintf(err.Error()))
}

return config
}
95 changes: 95 additions & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module csh/cluesheet

go 1.24.2

require (
github.com/DataDog/dd-trace-go/contrib/gorilla/mux/v2 v2.1.0-dev.1
github.com/DataDog/dd-trace-go/contrib/jackc/pgx.v5/v2 v2.1.0-dev.1
github.com/DataDog/dd-trace-go/v2 v2.1.0-dev.1
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/jackc/pgx/v5 v5.6.0
github.com/spf13/viper v1.20.1
go.uber.org/zap v1.27.0
)

require (
github.com/DataDog/appsec-internal-go v1.11.2 // indirect
github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/proto v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/version v0.64.0-rc.1 // indirect
github.com/DataDog/datadog-go/v5 v5.6.0 // indirect
github.com/DataDog/dd-trace-go/contrib/net/http/v2 v2.1.0-dev.1 // indirect
github.com/DataDog/go-libddwaf/v3 v3.5.4 // indirect
github.com/DataDog/go-runtime-metrics-internal v0.0.4-0.20241206090539-a14610dc22b6 // indirect
github.com/DataDog/go-sqllexer v0.1.0 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.26.0 // indirect
github.com/DataDog/sketches-go v1.4.7 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/outcaste-io/ristretto v0.2.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tinylib/msgp v1.2.5 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/collector/component v0.120.0 // indirect
go.opentelemetry.io/collector/pdata v1.26.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.120.0 // indirect
go.opentelemetry.io/collector/semconv v0.120.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250219182151-9fdb1cabc7b2 // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading