Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.PHONY: all
all:
Comment thread
christiannicola marked this conversation as resolved.
@CGO_ENABLED=0 go build -ldflags '-s -w' -o growteer-api ./cmd/growteer-api/...

.PHONY: lint
lint:
@golangci-lint run
Expand Down
20 changes: 19 additions & 1 deletion cmd/growteer-api/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"time"

"github.com/growteer/api/internal/api"
"github.com/growteer/api/internal/infrastructure/environment"
"github.com/growteer/api/internal/infrastructure/mongodb"
"github.com/growteer/api/internal/infrastructure/tokens"
)

func configureLogging() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)
}

func main() {
configureLogging()

env := environment.Load()
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, os.Interrupt)
Expand All @@ -26,5 +35,14 @@ func main() {

<-sig

slog.Info("shutting down")
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

if err := server.Shutdown(ctx); err != nil {
slog.Error("unable to shutdown gracefully", "err", err)

os.Exit(1)
}

slog.Info("shutting down...")
}
34 changes: 34 additions & 0 deletions cmd/growteer-api/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"os"
"sync"
"testing"
"time"

"github.com/test-go/testify/assert"
)

func TestMain(t *testing.T) {
assert.NoError(t, os.Setenv("HTTP_PORT", "8888"))

wg := sync.WaitGroup{}
wg.Add(2)

go func() {
defer wg.Done()
assert.NotPanics(t, func() {
main()
})
}()

go func() {
defer wg.Done()

c := time.Tick(time.Second * 3)
<-c
assert.NoError(t, sendInterruptSignal(os.Getpid()))
}()

wg.Wait()
}
16 changes: 16 additions & 0 deletions cmd/growteer-api/main_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !windows

package main

import (
"os"
)

func sendInterruptSignal(pid int) error {
proc, err := os.FindProcess(pid)
if err != nil {
return err
}

return proc.Signal(os.Interrupt)
}
24 changes: 24 additions & 0 deletions cmd/growteer-api/main_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build windows

package main

import (
"golang.org/x/sys/windows"
)

func sendInterruptSignal(pid int) error {
// NOTE (c.nicola): PROCESS_TERMINATE is more or less the equivalent to signal.SIGTERM.
// Windows does not have interrupt signals (at least not in Go), so
// we need to use the windows module and terminate the process.
// This won't trigger the graceful shutdown routines, so keep that in mind.
proc, err := windows.OpenProcess(windows.PROCESS_TERMINATE, false, uint32(pid))
if err != nil {
return err
}

if err = windows.TerminateProcess(proc, 0); err != nil {
return err
}

return windows.CloseHandle(proc)
}
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ buildGoApplication {
subPackages = [ "cmd/growteer-api" ];
modules = ./gomod2nix.toml;

# NOTE (c.nicola): disabled, run `nix develop -c make test` instead
doCheck = false;

CGO_ENABLED = 0;

ldflags = [ "-s -w" ];
Expand Down
54 changes: 23 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@ module github.com/growteer/api

go 1.24.4

replace gopkg.in/yaml.v2 v2.4.0 => gopkg.in/yaml.v3 v3.0.0

replace github.com/fatih/color v1.18.0 => github.com/fatih/color v1.16.0

replace github.com/mattn/go-colorable v0.1.13 => github.com/mattn/go-colorable v0.1.14

require (
github.com/99designs/gqlgen v0.17.60
github.com/gagliardetto/solana-go v1.12.0
github.com/99designs/gqlgen v0.17.76
github.com/gagliardetto/solana-go v1.13.0
github.com/go-chi/chi/v5 v5.2.2
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/golang-jwt/jwt/v5 v5.2.3
github.com/joho/godotenv v1.5.1
github.com/mr-tron/base58 v1.2.0
github.com/rs/cors v1.11.1
github.com/stretchr/testify v1.10.0
github.com/test-go/testify v1.1.4
github.com/vektah/gqlparser/v2 v2.5.20
github.com/vrischmann/envconfig v1.3.0
go.mongodb.org/mongo-driver v1.17.1
golang.org/x/net v0.38.0
github.com/vektah/gqlparser/v2 v2.5.30
github.com/vrischmann/envconfig v1.4.1
go.mongodb.org/mongo-driver v1.17.4
golang.org/x/net v0.42.0
)

require (
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/agnivade/levenshtein v1.2.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/agnivade/levenshtein v1.2.1 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gagliardetto/binary v0.8.0 // indirect
github.com/gagliardetto/treeout v0.1.4 // indirect
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -50,21 +44,19 @@ require (
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 // indirect
github.com/streamingfast/logging v0.0.0-20250724202230-68ac6cdda4bf // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/term v0.33.0 // indirect
golang.org/x/text v0.27.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading