Skip to content
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
22 changes: 11 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: Go

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
59 changes: 59 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"context"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"time"

"github.com/felipefrizzo/brazilian-zipcode-api/internal/config"
"github.com/felipefrizzo/brazilian-zipcode-api/internal/server"
)

func main() {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
logger.Info("starting server")

cfg, err := config.New()
if err != nil {
logger.Error("failed to create config", slog.String("error", err.Error()))
os.Exit(1)
}

srvr, err := server.New(logger, cfg)
if err != nil {
logger.Error("failed to create server", slog.String("error", err.Error()))
os.Exit(1)
}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

var wg sync.WaitGroup
wg.Add(1)

go func() {
defer wg.Done()
logger.Info(fmt.Sprintf("server is running on port %s", cfg.ServerPort))
if err := srvr.Server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logger.Error("server error", slog.String("error", err.Error()))
}
}()

<-ctx.Done()

logger.Info("shutting down server")
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := srvr.Server.Shutdown(shutdownCtx); err != nil {
logger.Error("server shutdown error", slog.String("error", err.Error()))
}

wg.Wait()
}
56 changes: 0 additions & 56 deletions cmd/server.go

This file was deleted.

42 changes: 21 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module github.com/felipefrizzo/brazilian-zipcode-api

go 1.17
go 1.24.2

require (
github.com/caarlos0/env/v6 v6.8.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/stretchr/testify v1.6.1
go.mongodb.org/mongo-driver v1.8.1
github.com/julienschmidt/httprouter v1.3.0
github.com/mitchellh/mapstructure v1.5.0
github.com/redis/go-redis/v9 v9.8.0
github.com/richardwilkes/toolbox v1.123.1
github.com/spf13/viper v1.20.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/text v0.21.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/sagikazarmark/locafero v0.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.8.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading