diff --git a/.env b/.env index c80812f..ee6fab9 100644 --- a/.env +++ b/.env @@ -2,14 +2,14 @@ # Images IMAGE_VERSION=1.0.0 -IMAGE_NAME=ghcr.io/brittonhayes/warhammer +IMAGE_NAME=ghcr.io/brittonhayes/aos # Platform ENV_PLATFORM=local # Service -WARHAMMER_SERVICE_NAME=warhammerd -WARHAMMER_SERVICE_PORT=8080 +SERVICE_NAME=aos +SERVICE_PORT=8080 # OpenTelemetry Collector OTEL_COLLECTOR_HOST=otel_collector @@ -19,7 +19,7 @@ OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTEL_COLLECTOR_HOST}:${OTEL_COLLECTOR_PORT_ PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:8080/oltp-http/v1/traces # OpenTelemetry Resource Definitions -OTEL_RESOURCE_ATTRIBUTES="service.namespace=warhammerd" +OTEL_RESOURCE_ATTRIBUTES="service.namespace=aos" # Metrics Temporality OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a581aee..516ba8b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: go-version: ${{ matrix.go-version }} - name: Build - run: go build -o bin/warhammerd ./cmd/warhammerd + run: go build -o bin/aos ./cmd/aos - name: Test run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f54612..edb9350 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + IMAGE_NAME: brittonhayes/aos jobs: build-and-push-image: diff --git a/Dockerfile b/Dockerfile index bee89aa..dda4806 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,17 +9,17 @@ COPY go.mod ./ RUN go mod download COPY . /src/ -RUN CGO_ENABLED=0 go build -o /bin/warhammerd cmd/warhammerd/main.go +RUN CGO_ENABLED=0 go build -o /bin/aos cmd/aos/main.go # STAGE 2 FROM gcr.io/distroless/static-debian11:nonroot LABEL maintainer="brittonhayes" -COPY --from=builder --chown=nonroot:nonroot /bin/warhammerd /bin/warhammerd +COPY --from=builder --chown=nonroot:nonroot /bin/aos /bin/aos EXPOSE 8080 -ENTRYPOINT [ "/bin/warhammerd" ] +ENTRYPOINT [ "/bin/aos" ] -CMD ["/bin/warhammerd"] \ No newline at end of file +CMD ["/bin/aos"] \ No newline at end of file diff --git a/Procfile b/Procfile index 9748291..019cb10 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -process: /bin/warhammerd \ No newline at end of file +process: /bin/aos \ No newline at end of file diff --git a/README.md b/README.md index 93c9c93..c9a4618 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Warhammer +# AoS -[![Go Reference](https://pkg.go.dev/badge/github.com/brittonhayes/warhammer.svg)](https://pkg.go.dev/github.com/brittonhayes/warhammer) -[![Go Report Card](https://goreportcard.com/badge/github.com/brittonhayes/warhammer)](https://goreportcard.com/report/github.com/brittonhayes/warhammer) +[![Go Reference](https://pkg.go.dev/badge/github.com/brittonhayes/aos.svg)](https://pkg.go.dev/github.com/brittonhayes/aos) +[![Go Report Card](https://goreportcard.com/badge/github.com/brittonhayes/aos)](https://goreportcard.com/report/github.com/brittonhayes/aos) -> A Warhammer: Age of Sigmar REST API built with Go and Sqlite. +> An unnoficial AoS REST API built with Go and Sqlite. ## ✨ Try the API (hosted) @@ -28,11 +28,11 @@ task up API documentation is available in YAML format within the repository. The OpenAPI spec is used to generate the transport logic thanks to [goapi-gen](https://github.com/discord-gophers/goapi-gen). -- [View the OpenAPI Spec](https://github.com/brittonhayes/warhammer/blob/main/api/openapi.yaml) +- [View the OpenAPI Spec](https://github.com/brittonhayes/aos/blob/main/api/openapi.yaml) ## 🗄️ Adding or Editing Data -All application data used to seed the database is editable in the [fixtures/](https://github.com/brittonhayes/warhammer/blob/main/fixtures/) directory. The API is built to be self-seeding and read-only, so if there is a need to add more data, simply add it to the fixtures files, rebuild and redeploy the API. +All application data used to seed the database is editable in the [fixtures/](https://github.com/brittonhayes/aos/blob/main/fixtures/) directory. The API is built to be self-seeding and read-only, so if there is a need to add more data, simply add it to the fixtures files, rebuild and redeploy the API. ### Example - Adding a new alliance @@ -50,7 +50,7 @@ To add a new entry to the database, just add a new object to the appropriate yam + description: The forces of Chaos seek to corrupt and dominate the Mortal Realms. Made up of daemons, monsters, and twisted beings, they spread destruction wherever theygo. ``` -- [View the data](https://github.com/brittonhayes/warhammer/blob/main/fixtures/fixtures.yaml) +- [View the data](https://github.com/brittonhayes/aos/blob/main/fixtures/fixtures.yaml) ## API Endpoints @@ -76,15 +76,15 @@ Application observability is instrumented with OpenTelemetry. Telemetry is avail When running with docker-compose, the following services are available: -- API is available at [http://warhammer.localhost:8090](http://warhammer.localhost:8090) -- Documentation is available at [http://warhammer.localhost:8090/docs](http://warhammer.localhost:8090/docs) +- API is available at [http://aos.localhost:8090](http://aos.localhost:8090) +- Documentation is available at [http://aos.localhost:8090/docs](http://aos.localhost:8090/docs) - Traefik Dashboard is available at [http://localhost:8080](http://localhost:8080) - Prometheus is available at [http://prometheus.localhost:8090](http://prometheus.localhost:8090) - Grafana is available at [http://grafana.localhost:8090](http://grafana.localhost:8090) ## 🙋 FAQ -- **Q: Where is X {unit,alliance,etc}?** - A: Waiting for you to add it! See the [fixtures/](https://github.com/brittonhayes/warhammer/blob/main/fixtures/) directory for more information. +- **Q: Where is X {unit,alliance,etc}?** - A: Waiting for you to add it! See the [fixtures/](https://github.com/brittonhayes/aos/blob/main/fixtures/) directory for more information. ## ⚖️ Copyright and Data Ownership @@ -99,4 +99,4 @@ through a REST interface rather than the usual PDF. If you consume the data served through this API, be aware that you are also obligated to respect [Games Workshop's](https://www.games-workshop.com) [intellectual property guidelines](https://www.games-workshop.com/en-US/Intellectual-Property-Guidelines). -For more information, view our [Contributing Guidelines](https://github.com/brittonhayes/warhammer/blob/main/CONTRIBUTING.md). \ No newline at end of file +For more information, view our [Contributing Guidelines](https://github.com/brittonhayes/aos/blob/main/CONTRIBUTING.md). \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index dc2e1ee..cb7c83d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,7 +5,7 @@ version: '3' tasks: default: cmds: - - go run ./cmd/warhammerd + - go run ./cmd/aos up: desc: "Start the application with docker-compose" diff --git a/warhammer.go b/aos.go similarity index 86% rename from warhammer.go rename to aos.go index df51c9c..14d1d62 100644 --- a/warhammer.go +++ b/aos.go @@ -1,17 +1,17 @@ -// Package warhammer provides the WarhammerRepository interface for the Warhammer REST API and services +// Package aos provides the Repository interface for the AoS REST API and services // -//go:generate goapi-gen -generate types,server,spec -package api --out api/warhammer.gen.go ./api/openapi.yaml +//go:generate goapi-gen -generate types,server,spec -package api --out api/api.gen.go ./api/openapi.yaml //go:generate npx @redocly/cli build-docs api/openapi.yaml -o web/index.html -package warhammer +package aos import ( "context" "io/fs" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) -type WarhammerRepository interface { +type Repository interface { GetArmyByID(ctx context.Context, id string) (*api.Army, error) GetArmies(ctx context.Context) ([]api.Army, error) diff --git a/api/warhammer.gen.go b/api/api.gen.go similarity index 94% rename from api/warhammer.gen.go rename to api/api.gen.go index 3c9464f..a537ce0 100644 --- a/api/warhammer.gen.go +++ b/api/api.gen.go @@ -1265,34 +1265,34 @@ func WithErrorHandler(handler func(w http.ResponseWriter, r *http.Request, err e // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9RaTW/bOBP+KwLf97ALOFHaBnvwLdtu22C3uwXSIIeiMGhpLLPhh0pSSdQi/31BSrK+", - "KItq7Kx9amoNZ8h5nmeGlPgDRYKlggPXCs1/IBWtgWH758WSUKJz82cqRQpSE7APYlCRJKkmgpv/6jwF", - "NEdKS8IT9DhDHDNwPHicVb+I5VeItDG9oBQSgnkE/TALEve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l8eXZWHIi4Bm6TidOUljQKv6pC97U/v81Aqw53Tv/dPQ36509j", - "dX52Pmki2+IXR0RHqMaR0BTFjDFsNpROyhiLJt/CHyR+HCNdRY9lHpB4O+t+zy/fjBGvIESbdhJ0JnnF", - "BCONmgg2Zt2ntcxgn2Tw5cAhY95GrABdMuJTXwozF8jVk2eQmmT5sYmsyE4j1R7SkizfIirJ8glyMr6O", - "SEgW4cNFtEbGIhptztNbxVOaOcB8XT3xaskR0flOmvGzNMbXzlcbB63WEqgGtuNqtaAMqtUkwV+tFcBH", - "otYC4YNFtIGMRTQW0Xatmi17LKKMAdd2li5E3xgvo0nV8KDDtWa0vcbNSWhJOLaS7eJ1qMns58bm1O7G", - "T6rd+HgpbO/3nTWx9VbheTYWvRcZR1Szuhl1wTJexTrnsMF61sqUf2HrH/OOpMR1mHGwTHDi16CCKj5p", - "EW+JNgYM0eCqafJMIt18mjtGkTZy6oTGV6bliHxEplWupsp04/7IZFpz48Bl2sHPcmFtP+F+34p+YROU", - "X2sdsL8vnewx0+Wn5sNNcTtJNrebizxb615h5cjqdfnA64xmvOznhWmnxE+INeGV6UDUDWMnR61GTota", - "fO+ZEq38QuSIUn9leJZj78A9sEPuTgXza6mM9yGLymD3MSnwbzoVwkfSagp8DxbPBjIdQMPWBZDhUlhZ", - "2e9q24G+qGzfCvkU0NtBD4ICT7vAc7hyH0LXkuW+utAw3i0bpg5i3DSfevXNjb/9NM+6oUwK5NNVerG6", - "Ny0mR+1d1Zi0VEW+Tw9p70xMCmMva0xHzl7x+M+FW9/cOa5O3VBdR7DjPbvGabCeb9LiX8hb6B9JC2+g", - "f7Bod9GywxXIOzcYf4kI06B43rrJMg8NSYobKqfUWK2FMhvUroePUsRZZC/UONyoeRhioU5wSk4jwdDj", - "l8d/AwAA//9oAjB3ADMAAA==", + "H4sIAAAAAAAC/9RaW2/bOBP9KwK/72EXcCK3DfbBb95eg93uFpsGfSgKg5bGNhteVJJKohb57wtSknWj", + "LKqxs/ZTU2s4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u73f7c", + "MgAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/api/openapi.yaml b/api/openapi.yaml index daf1fd6..35f0c2d 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -1,14 +1,14 @@ openapi: "3.1.0" info: - title: Warhammer Age of Sigmar API (Unofficial) + title: AoS API (Unofficial) version: 1.0.0 - description: API specification for a Warhammer Age of Sigmar API (Unofficial) + description: API specification for an AoS REST API (Unofficial) license: name: MIT url: https://opensource.org/licenses/MIT security: [] servers: -- url: http://warhammer.localhost +- url: http://aos-api.localhost description: Local server - url: https://aos-api.com description: Production server diff --git a/cmd/warhammerd/main.go b/cmd/aos/main.go similarity index 86% rename from cmd/warhammerd/main.go rename to cmd/aos/main.go index 7ea01af..c921f21 100644 --- a/cmd/warhammerd/main.go +++ b/cmd/aos/main.go @@ -8,13 +8,13 @@ import ( "sort" "time" - "github.com/brittonhayes/warhammer" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/fixtures" - "github.com/brittonhayes/warhammer/internal/logging" - "github.com/brittonhayes/warhammer/internal/tracing" - "github.com/brittonhayes/warhammer/service" - "github.com/brittonhayes/warhammer/sqlite" + "github.com/brittonhayes/aos" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/fixtures" + "github.com/brittonhayes/aos/internal/logging" + "github.com/brittonhayes/aos/internal/tracing" + "github.com/brittonhayes/aos/service" + "github.com/brittonhayes/aos/sqlite" apimw "github.com/discord-gophers/goapi-gen/middleware" "github.com/go-chi/chi/v5" @@ -29,16 +29,16 @@ import ( func main() { var ( - repo warhammer.WarhammerRepository + repo aos.Repository ) app := &cli.App{ - Name: "warhammerd", - Usage: "the warhammer api server", + Name: "aos", + Usage: "AoS api server", Suggest: true, Before: func(c *cli.Context) error { if c.Bool("migrate") { - repo = sqlite.NewWarhammerRepository(c.String("db")) + repo = sqlite.NewRepository(c.String("db")) err := repo.Init(c.Context) if err != nil { @@ -59,7 +59,7 @@ func main() { fixtures.WARSCROLLS, } - err = repo.Seed(c.Context, warhammer.FIXTURES, data...) + err = repo.Seed(c.Context, aos.FIXTURES, data...) if err != nil { return err } @@ -67,10 +67,10 @@ func main() { return nil }, Action: func(c *cli.Context) error { - repo = sqlite.NewWarhammerRepository(c.String("db")) + repo = sqlite.NewRepository(c.String("db")) // Create an instance of our handler which satisfies the generated interface - s := service.NewWarhammerService(repo) + s := service.New(repo) swagger, err := api.GetSwagger() if err != nil { @@ -158,14 +158,14 @@ func main() { Name: "port", Aliases: []string{"p"}, Value: 8080, - EnvVars: []string{"WARHAMMER_SERVICE_PORT", "PORT"}, + EnvVars: []string{"PORT"}, Usage: "port to listen on", }, &cli.StringFlag{ Name: "service", Aliases: []string{"s"}, - Value: "warhammerd", - EnvVars: []string{"WARHAMMER_SERVICE_NAME", "SERVICE_NAME"}, + Value: "aos", + EnvVars: []string{"SERVICE_NAME"}, Usage: "customize the service name", }, &cli.StringFlag{ @@ -176,14 +176,14 @@ func main() { }, &cli.StringFlag{ Name: "db", - Value: "file:warhammer.db", + Value: "file:aos.db", EnvVars: []string{"DATABASE_URL"}, Usage: "database url", }, &cli.BoolFlag{ Name: "tracing", Aliases: []string{"t"}, - Value: true, + Value: false, EnvVars: []string{"TRACING"}, Usage: "enable tracing", }, @@ -203,7 +203,7 @@ func main() { return repo.Migrate(c.Context) }, Before: func(c *cli.Context) error { - repo = sqlite.NewWarhammerRepository(c.String("db")) + repo = sqlite.NewRepository(c.String("db")) return nil }, Subcommands: []*cli.Command{ @@ -258,7 +258,7 @@ func main() { fixtures.WARSCROLLS, } - return repo.Seed(c.Context, warhammer.FIXTURES, data...) + return repo.Seed(c.Context, aos.FIXTURES, data...) }, }, }, diff --git a/config/prometheus-config.yaml b/config/prometheus-config.yaml index 9f10d1a..474d687 100644 --- a/config/prometheus-config.yaml +++ b/config/prometheus-config.yaml @@ -24,6 +24,6 @@ scrape_configs: static_configs: - targets: ['prometheus:9090'] -- job_name: 'warhammer' +- job_name: 'aos' static_configs: - - targets: ['warhammer:8080'] + - targets: ['aos:8080'] diff --git a/docker-compose.yml b/docker-compose.yml index 34168da..4fcf93b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ volumes: networks: default: - name: warhammer + name: aos driver: bridge services: @@ -25,25 +25,25 @@ services: volumes: - "/var/run/docker.sock:/var/run/docker.sock:ro" - warhammer: - container_name: warhammer - image: ghcr.io:brittonhayes/warhammer:latest + aos: + container_name: aos + image: ghcr.io:brittonhayes/aos:latest build: dockerfile: ./Dockerfile context: . labels: - "traefik.enable=true" - "traefik.docker.network=web" - - "traefik.http.routers.warhammer.rule=Host(`warhammer.localhost`) && PathPrefix(`/api`) && Method(`GET`, `OPTIONS`)" - - "traefik.http.routers.warhammer.entrypoints=web" - - "traefik.http.middlewares.warhammer-ratelimit.ratelimit.average=250" - - "traefik.http.middlewares.warhammer-ratelimit.ratelimit.burst=100" - - "traefik.http.middlewares.warhammer-strip-api.stripprefix.prefixes=/api" - - "traefik.http.routers.warhammer.middlewares=warhammer-strip-api" - - "traefik.http.services.warhammer.loadbalancer.server.port=8080" + - "traefik.http.routers.aos-api.rule=Host(`aos-api.localhost`) && PathPrefix(`/api`) && Method(`GET`, `OPTIONS`)" + - "traefik.http.routers.aos-api.entrypoints=web" + - "traefik.http.middlewares.aos-api-ratelimit.ratelimit.average=250" + - "traefik.http.middlewares.aos-api-ratelimit.ratelimit.burst=100" + - "traefik.http.middlewares.aos-api-strip-api.stripprefix.prefixes=/api" + - "traefik.http.routers.aos-api.middlewares=aos-api-strip-api" + - "traefik.http.services.aos-api.loadbalancer.server.port=8080" environment: - - WARHAMMER_SERVICE_NAME - - WARHAMMER_SERVICE_PORT + - SERVICE_NAME + - SERVICE_PORT - OTEL_EXPORTER_OTLP_ENDPOINT - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE - OTEL_RESOURCE_ATTRIBUTES diff --git a/embed.go b/embed.go index 807e848..cfba223 100644 --- a/embed.go +++ b/embed.go @@ -1,4 +1,4 @@ -package warhammer +package aos import ( "embed" diff --git a/go.mod b/go.mod index 91558c8..c430566 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/brittonhayes/warhammer +module github.com/brittonhayes/aos go 1.20 diff --git a/railway.toml b/railway.toml index 3597f5c..d09db9f 100644 --- a/railway.toml +++ b/railway.toml @@ -1,4 +1,4 @@ [deploy] -startCommand = "/bin/warhammerd --migrate --tracing=false" +startCommand = "/bin/aos --migrate --tracing=false" restartPolicyType = "on_failure" restartPolicyMaxRetries = 5 \ No newline at end of file diff --git a/service/allegiance.go b/service/allegiance.go index 66bdcce..b730cf4 100644 --- a/service/allegiance.go +++ b/service/allegiance.go @@ -3,8 +3,8 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/internal/logging" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/internal/logging" "github.com/sirupsen/logrus" ) @@ -13,7 +13,7 @@ const ( ErrAllegiancesNotFound = "No allegiances found" ) -func (s *WarhammerService) GetAllegianceByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetAllegianceByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetAllegianceByID", @@ -28,7 +28,7 @@ func (s *WarhammerService) GetAllegianceByID(w http.ResponseWriter, r *http.Requ return api.GetAllegianceByIDJSON200Response(*allegiance) } -func (s *WarhammerService) GetAllegiances(w http.ResponseWriter, r *http.Request, params api.GetAllegiancesParams) *api.Response { +func (s *Service) GetAllegiances(w http.ResponseWriter, r *http.Request, params api.GetAllegiancesParams) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetAllegiances", diff --git a/service/alliance.go b/service/alliance.go index 75a5f79..5beaab9 100644 --- a/service/alliance.go +++ b/service/alliance.go @@ -3,8 +3,8 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/internal/logging" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/internal/logging" "github.com/sirupsen/logrus" ) @@ -13,7 +13,7 @@ const ( ErrAlliancesNotFound = "No alliances found" ) -func (s *WarhammerService) GetGrandAllianceByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetGrandAllianceByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetGrandAllianceByID", @@ -28,7 +28,7 @@ func (s *WarhammerService) GetGrandAllianceByID(w http.ResponseWriter, r *http.R return api.GetGrandAllianceByIDJSON200Response(*alliance) } -func (s *WarhammerService) GetGrandAlliances(w http.ResponseWriter, r *http.Request) *api.Response { +func (s *Service) GetGrandAlliances(w http.ResponseWriter, r *http.Request) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetGrandAlliances", diff --git a/service/army.go b/service/army.go index 26355d2..d952160 100644 --- a/service/army.go +++ b/service/army.go @@ -3,8 +3,8 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/internal/logging" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/internal/logging" "github.com/sirupsen/logrus" ) @@ -13,7 +13,7 @@ const ( ErrArmiesNotFound = "No armies found" ) -func (s *WarhammerService) GetArmyByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetArmyByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetArmyByID", @@ -28,7 +28,7 @@ func (s *WarhammerService) GetArmyByID(w http.ResponseWriter, r *http.Request, i return api.GetArmyByIDJSON200Response(*army) } -func (s *WarhammerService) GetArmies(w http.ResponseWriter, r *http.Request) *api.Response { +func (s *Service) GetArmies(w http.ResponseWriter, r *http.Request) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetArmies", diff --git a/service/city.go b/service/city.go index 8f254bd..3b4e9e7 100644 --- a/service/city.go +++ b/service/city.go @@ -3,14 +3,14 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) const ( ErrCitiesNotFound = "cities not found" ) -func (s *WarhammerService) GetCities(w http.ResponseWriter, r *http.Request, params api.GetCitiesParams) *api.Response { +func (s *Service) GetCities(w http.ResponseWriter, r *http.Request, params api.GetCitiesParams) *api.Response { cities, err := s.repo.GetCities(r.Context(), params) if err != nil { return api.GetCitiesJSON404Response(api.Error{ @@ -22,7 +22,7 @@ func (s *WarhammerService) GetCities(w http.ResponseWriter, r *http.Request, par return api.GetCitiesJSON200Response(cities) } -func (s *WarhammerService) GetCityByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetCityByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { city, err := s.repo.GetCityByID(r.Context(), id) if err != nil { return api.GetCityByIDJSON404Response(api.Error{ diff --git a/service/doc.go b/service/doc.go index 93671c7..0ecaa5d 100644 --- a/service/doc.go +++ b/service/doc.go @@ -3,16 +3,16 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos" + "github.com/brittonhayes/aos/api" ) -func (s *WarhammerService) GetDocs(w http.ResponseWriter, r *http.Request) *api.Response { +func (s *Service) GetDocs(w http.ResponseWriter, r *http.Request) *api.Response { resp := api.Response{} resp.ContentType("text/html") resp.Status(http.StatusOK) - w.Write(warhammer.OPEN_API_DOCS) + w.Write(aos.OPEN_API_DOCS) return &resp } diff --git a/service/healthz.go b/service/healthz.go index 36ebd49..659eab9 100644 --- a/service/healthz.go +++ b/service/healthz.go @@ -3,10 +3,10 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) -func (s *WarhammerService) GetHealthz(w http.ResponseWriter, r *http.Request) *api.Response { +func (s *Service) GetHealthz(w http.ResponseWriter, r *http.Request) *api.Response { resp := api.Health{Status: "ok"} return api.GetHealthzJSON200Response(resp) } diff --git a/service/service.go b/service/service.go index cf68439..1736500 100644 --- a/service/service.go +++ b/service/service.go @@ -1,18 +1,18 @@ package service import ( - "github.com/brittonhayes/warhammer" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos" + "github.com/brittonhayes/aos/api" ) -type WarhammerService struct { - repo warhammer.WarhammerRepository +type Service struct { + repo aos.Repository } -var _ api.ServerInterface = (*WarhammerService)(nil) +var _ api.ServerInterface = (*Service)(nil) -func NewWarhammerService(repository warhammer.WarhammerRepository) api.ServerInterface { - return &WarhammerService{ +func New(repository aos.Repository) api.ServerInterface { + return &Service{ repo: repository, } } diff --git a/service/strategy.go b/service/strategy.go index 5050972..90f7b58 100644 --- a/service/strategy.go +++ b/service/strategy.go @@ -3,8 +3,8 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/internal/logging" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/internal/logging" "github.com/sirupsen/logrus" ) @@ -13,7 +13,7 @@ const ( ErrGrandStrategiesNotFound = "No strategys found" ) -func (s *WarhammerService) GetGrandStrategyByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetGrandStrategyByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetStrategyByID", @@ -28,7 +28,7 @@ func (s *WarhammerService) GetGrandStrategyByID(w http.ResponseWriter, r *http.R return api.GetGrandStrategyByIDJSON200Response(api.GrandStrategy(*strategy)) } -func (s *WarhammerService) GetGrandStrategies(w http.ResponseWriter, r *http.Request) *api.Response { +func (s *Service) GetGrandStrategies(w http.ResponseWriter, r *http.Request) *api.Response { logging.NewLogrus(r.Context()).WithFields(logrus.Fields{ "event": "GetStrategies", diff --git a/service/unit.go b/service/unit.go index 51e47f1..4ec2cf8 100644 --- a/service/unit.go +++ b/service/unit.go @@ -3,7 +3,7 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) const ( @@ -11,7 +11,7 @@ const ( ErrUnitsNotFound = "No units found" ) -func (s *WarhammerService) GetUnitByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetUnitByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { unit, err := s.repo.GetUnitByID(r.Context(), id) if err != nil { return api.GetUnitByIDJSON404Response(api.Error{Code: http.StatusNotFound, Message: ErrUnitNotFound}) @@ -20,7 +20,7 @@ func (s *WarhammerService) GetUnitByID(w http.ResponseWriter, r *http.Request, i return api.GetUnitByIDJSON200Response(*unit) } -func (s *WarhammerService) GetUnits(w http.ResponseWriter, r *http.Request, params api.GetUnitsParams) *api.Response { +func (s *Service) GetUnits(w http.ResponseWriter, r *http.Request, params api.GetUnitsParams) *api.Response { units, err := s.repo.GetUnits(r.Context(), params) if err != nil { return api.GetUnitsJSON404Response(api.Error{Code: http.StatusNotFound, Message: ErrUnitsNotFound}) @@ -29,7 +29,7 @@ func (s *WarhammerService) GetUnits(w http.ResponseWriter, r *http.Request, para return api.GetUnitsJSON200Response(units) } -func (s *WarhammerService) GetAbilitiesForUnitByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetAbilitiesForUnitByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { abilities, err := s.repo.GetAbilitiesForUnitByID(r.Context(), id) if err != nil { return api.GetAbilitiesForUnitByIDJSON404Response(api.Error{Code: http.StatusNotFound, Message: ErrUnitNotFound}) diff --git a/service/warscroll.go b/service/warscroll.go index 945ac35..edc28ef 100644 --- a/service/warscroll.go +++ b/service/warscroll.go @@ -3,7 +3,7 @@ package service import ( "net/http" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "go.opentelemetry.io/otel/trace" @@ -14,7 +14,7 @@ const ( ErrWarscrollsNotFound = "No warscrolls found" ) -func (s *WarhammerService) GetWarscrollByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { +func (s *Service) GetWarscrollByID(w http.ResponseWriter, r *http.Request, id string) *api.Response { span := trace.SpanFromContext(r.Context()) defer span.End() @@ -40,7 +40,7 @@ func (s *WarhammerService) GetWarscrollByID(w http.ResponseWriter, r *http.Reque return api.GetWarscrollByIDJSON200Response(*warscroll) } -func (s *WarhammerService) GetWarscrolls(w http.ResponseWriter, r *http.Request, params api.GetWarscrollsParams) *api.Response { +func (s *Service) GetWarscrolls(w http.ResponseWriter, r *http.Request, params api.GetWarscrollsParams) *api.Response { span := trace.SpanFromContext(r.Context()) defer span.End() diff --git a/sqlite/allegiance.go b/sqlite/allegiance.go index dcd4c66..ccefee6 100644 --- a/sqlite/allegiance.go +++ b/sqlite/allegiance.go @@ -3,11 +3,11 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "github.com/uptrace/bun" ) -func (r *warhammerRepository) GetAllegianceByID(ctx context.Context, id string) (*api.Allegiance, error) { +func (r *repository) GetAllegianceByID(ctx context.Context, id string) (*api.Allegiance, error) { var allegiance api.Allegiance err := r.db.NewSelect().Model(&allegiance).Where("id = ?", id).Scan(ctx) if err != nil { @@ -17,7 +17,7 @@ func (r *warhammerRepository) GetAllegianceByID(ctx context.Context, id string) return &allegiance, nil } -func (r *warhammerRepository) allegiancesFilterQuery(query *bun.SelectQuery, params api.GetAllegiancesParams) (*bun.SelectQuery, error) { +func (r *repository) allegiancesFilterQuery(query *bun.SelectQuery, params api.GetAllegiancesParams) (*bun.SelectQuery, error) { if params.GrandAlliance != nil { query = query.Where("grand_alliance = ?", params.GrandAlliance) } @@ -29,7 +29,7 @@ func (r *warhammerRepository) allegiancesFilterQuery(query *bun.SelectQuery, par return query, nil } -func (r *warhammerRepository) GetAllegiances(ctx context.Context, params api.GetAllegiancesParams) ([]api.Allegiance, error) { +func (r *repository) GetAllegiances(ctx context.Context, params api.GetAllegiancesParams) ([]api.Allegiance, error) { var allegiances []api.Allegiance query, err := r.allegiancesFilterQuery(r.db.NewSelect().Model(&allegiances), params) diff --git a/sqlite/alliance.go b/sqlite/alliance.go index 9282f1d..c740cf4 100644 --- a/sqlite/alliance.go +++ b/sqlite/alliance.go @@ -3,10 +3,10 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) -func (r *warhammerRepository) GetGrandAllianceByID(ctx context.Context, id string) (*api.GrandAlliance, error) { +func (r *repository) GetGrandAllianceByID(ctx context.Context, id string) (*api.GrandAlliance, error) { var grandAlliance api.GrandAlliance err := r.db.NewSelect().Model(&grandAlliance).Where("id = ?", id).Scan(ctx) if err != nil { @@ -16,7 +16,7 @@ func (r *warhammerRepository) GetGrandAllianceByID(ctx context.Context, id strin return &grandAlliance, nil } -func (r *warhammerRepository) GetGrandAlliances(ctx context.Context) ([]api.GrandAlliance, error) { +func (r *repository) GetGrandAlliances(ctx context.Context) ([]api.GrandAlliance, error) { var grandAlliances []api.GrandAlliance err := r.db.NewSelect().Model(&grandAlliances).Scan(ctx) if err != nil { diff --git a/sqlite/army.go b/sqlite/army.go index 239b8bd..bb7649e 100644 --- a/sqlite/army.go +++ b/sqlite/army.go @@ -3,10 +3,10 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) -func (r *warhammerRepository) GetArmyByID(ctx context.Context, id string) (*api.Army, error) { +func (r *repository) GetArmyByID(ctx context.Context, id string) (*api.Army, error) { var army api.Army err := r.db.NewSelect().Model(&army).Where("id = ?", id).Scan(ctx) if err != nil { @@ -16,7 +16,7 @@ func (r *warhammerRepository) GetArmyByID(ctx context.Context, id string) (*api. return &army, nil } -func (r *warhammerRepository) GetArmies(ctx context.Context) ([]api.Army, error) { +func (r *repository) GetArmies(ctx context.Context) ([]api.Army, error) { var armies []api.Army err := r.db.NewSelect().Model(&armies).Scan(ctx) if err != nil { @@ -26,7 +26,7 @@ func (r *warhammerRepository) GetArmies(ctx context.Context) ([]api.Army, error) return armies, nil } -func (r *warhammerRepository) UpdateArmyByID(ctx context.Context, id string, army *api.Army) (*api.Army, error) { +func (r *repository) UpdateArmyByID(ctx context.Context, id string, army *api.Army) (*api.Army, error) { _, err := r.db.NewUpdate().Model(army).Where("id = ?", id).Exec(ctx) if err != nil { return nil, err diff --git a/sqlite/city.go b/sqlite/city.go index af51f4f..ebf0947 100644 --- a/sqlite/city.go +++ b/sqlite/city.go @@ -3,11 +3,11 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "github.com/uptrace/bun" ) -func (r *warhammerRepository) citiesFilterQuery(query *bun.SelectQuery, params api.GetCitiesParams) (*bun.SelectQuery, error) { +func (r *repository) citiesFilterQuery(query *bun.SelectQuery, params api.GetCitiesParams) (*bun.SelectQuery, error) { if params.Name != nil { query = query.Where("? LIKE ?", bun.Ident("name"), *params.Name+"%") @@ -16,7 +16,7 @@ func (r *warhammerRepository) citiesFilterQuery(query *bun.SelectQuery, params a return query, nil } -func (r *warhammerRepository) GetCities(ctx context.Context, params api.GetCitiesParams) ([]api.City, error) { +func (r *repository) GetCities(ctx context.Context, params api.GetCitiesParams) ([]api.City, error) { var cities []api.City query, err := r.citiesFilterQuery(r.db.NewSelect().Model(&cities), params) @@ -32,7 +32,7 @@ func (r *warhammerRepository) GetCities(ctx context.Context, params api.GetCitie return cities, nil } -func (r *warhammerRepository) GetCityByID(ctx context.Context, id string) (*api.City, error) { +func (r *repository) GetCityByID(ctx context.Context, id string) (*api.City, error) { var city api.City err := r.db.NewSelect().Model(&city).Where("id = ?", id).Scan(ctx) diff --git a/sqlite/migrations/20230712031006_init.go b/sqlite/migrations/20230712031006_init.go index 737f5a8..6516c43 100644 --- a/sqlite/migrations/20230712031006_init.go +++ b/sqlite/migrations/20230712031006_init.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "github.com/uptrace/bun" ) diff --git a/sqlite/repository.go b/sqlite/repository.go index ae629a1..cf1aa7b 100644 --- a/sqlite/repository.go +++ b/sqlite/repository.go @@ -6,10 +6,10 @@ import ( "io/fs" "strings" - "github.com/brittonhayes/warhammer" - "github.com/brittonhayes/warhammer/api" - "github.com/brittonhayes/warhammer/internal/logging" - "github.com/brittonhayes/warhammer/sqlite/migrations" + "github.com/brittonhayes/aos" + "github.com/brittonhayes/aos/api" + "github.com/brittonhayes/aos/internal/logging" + "github.com/brittonhayes/aos/sqlite/migrations" "github.com/uptrace/bun" "github.com/uptrace/bun/dbfixture" "github.com/uptrace/bun/dialect/sqlitedialect" @@ -18,18 +18,18 @@ import ( "github.com/uptrace/bun/migrate" ) -type warhammerRepository struct { +type repository struct { m *migrate.Migrator db *bun.DB } const ( - DB_NAME = "warhammer" + DB_NAME = "aos" DEFAULT_LIMIT = 100 DEFAULT_OFFSET = 0 ) -func NewWarhammerRepository(connection string) warhammer.WarhammerRepository { +func NewRepository(connection string) aos.Repository { sqldb, err := sql.Open(sqliteshim.ShimName, connection) if err != nil { panic(err) @@ -43,18 +43,18 @@ func NewWarhammerRepository(connection string) warhammer.WarhammerRepository { migrator := migrate.NewMigrator(db, migrations.Migrations) - return &warhammerRepository{ + return &repository{ m: migrator, db: db, } } -func (r *warhammerRepository) Init(ctx context.Context) error { +func (r *repository) Init(ctx context.Context) error { logging.NewLogrus(ctx).Info("initializing database") return r.m.Init(ctx) } -func (r *warhammerRepository) Generate(ctx context.Context, name string) error { +func (r *repository) Generate(ctx context.Context, name string) error { name = strings.ReplaceAll(name, " ", "_") m, err := r.m.CreateGoMigration(ctx, name) @@ -67,7 +67,7 @@ func (r *warhammerRepository) Generate(ctx context.Context, name string) error { return nil } -func (r *warhammerRepository) Migrate(ctx context.Context) error { +func (r *repository) Migrate(ctx context.Context) error { logger := logging.NewLogrus(ctx) @@ -91,7 +91,7 @@ func (r *warhammerRepository) Migrate(ctx context.Context) error { return nil } -func (r *warhammerRepository) Seed(ctx context.Context, fsys fs.FS, names ...string) error { +func (r *repository) Seed(ctx context.Context, fsys fs.FS, names ...string) error { logger := logging.NewLogrus(ctx) models := []interface{}{ @@ -116,17 +116,17 @@ func (r *warhammerRepository) Seed(ctx context.Context, fsys fs.FS, names ...str return f.Load(ctx, fsys, names...) } -func (r *warhammerRepository) Lock(ctx context.Context) error { +func (r *repository) Lock(ctx context.Context) error { logging.NewLogrus(ctx).Info("locking database") return r.m.Lock(ctx) } -func (r *warhammerRepository) Unlock(ctx context.Context) error { +func (r *repository) Unlock(ctx context.Context) error { logging.NewLogrus(ctx).Info("unlocking database") return r.m.Unlock(ctx) } -func (r *warhammerRepository) Rollback(ctx context.Context) error { +func (r *repository) Rollback(ctx context.Context) error { logger := logging.NewLogrus(ctx) err := r.m.Lock(ctx) diff --git a/sqlite/strategy.go b/sqlite/strategy.go index 5bec2d1..b7954cc 100644 --- a/sqlite/strategy.go +++ b/sqlite/strategy.go @@ -3,10 +3,10 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" ) -func (r *warhammerRepository) GetGrandStrategyByID(ctx context.Context, id string) (*api.GrandStrategy, error) { +func (r *repository) GetGrandStrategyByID(ctx context.Context, id string) (*api.GrandStrategy, error) { var strategy api.GrandStrategy err := r.db.NewSelect().Model(&strategy).Where("id = ?", id).Scan(ctx) if err != nil { @@ -16,7 +16,7 @@ func (r *warhammerRepository) GetGrandStrategyByID(ctx context.Context, id strin return &strategy, nil } -func (r *warhammerRepository) GetGrandStrategies(ctx context.Context) ([]api.GrandStrategy, error) { +func (r *repository) GetGrandStrategies(ctx context.Context) ([]api.GrandStrategy, error) { var strategies []api.GrandStrategy err := r.db.NewSelect().Model(&strategies).Scan(ctx) if err != nil { diff --git a/sqlite/unit.go b/sqlite/unit.go index e1d3de1..21955a5 100644 --- a/sqlite/unit.go +++ b/sqlite/unit.go @@ -3,11 +3,11 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "github.com/uptrace/bun" ) -func (r *warhammerRepository) GetUnitByID(ctx context.Context, id string) (*api.Unit, error) { +func (r *repository) GetUnitByID(ctx context.Context, id string) (*api.Unit, error) { var unit api.Unit err := r.db.NewSelect().Model(&unit).Where("id = ?", id).Scan(ctx) if err != nil { @@ -17,7 +17,7 @@ func (r *warhammerRepository) GetUnitByID(ctx context.Context, id string) (*api. return &unit, nil } -func (r *warhammerRepository) unitsFilterQuery(query *bun.SelectQuery, params api.GetUnitsParams) (*bun.SelectQuery, error) { +func (r *repository) unitsFilterQuery(query *bun.SelectQuery, params api.GetUnitsParams) (*bun.SelectQuery, error) { if params.Name != nil { query = query.Where("? LIKE ?", bun.Ident("name"), *params.Name+"%") } @@ -37,7 +37,7 @@ func (r *warhammerRepository) unitsFilterQuery(query *bun.SelectQuery, params ap return query, nil } -func (r *warhammerRepository) GetUnits(ctx context.Context, params api.GetUnitsParams) ([]api.Unit, error) { +func (r *repository) GetUnits(ctx context.Context, params api.GetUnitsParams) ([]api.Unit, error) { var units []api.Unit query, err := r.unitsFilterQuery(r.db.NewSelect().Model(&units), params) @@ -53,7 +53,7 @@ func (r *warhammerRepository) GetUnits(ctx context.Context, params api.GetUnitsP return units, nil } -func (r *warhammerRepository) GetAbilitiesForUnitByID(ctx context.Context, id string) ([]api.Ability, error) { +func (r *repository) GetAbilitiesForUnitByID(ctx context.Context, id string) ([]api.Ability, error) { var unit api.Unit err := r.db.NewSelect().Model(&unit).Where("id = ?", id).Scan(ctx) if err != nil { diff --git a/sqlite/warscroll.go b/sqlite/warscroll.go index af0eed4..de9e3d1 100644 --- a/sqlite/warscroll.go +++ b/sqlite/warscroll.go @@ -3,11 +3,11 @@ package sqlite import ( "context" - "github.com/brittonhayes/warhammer/api" + "github.com/brittonhayes/aos/api" "github.com/uptrace/bun" ) -func (r *warhammerRepository) warscrollFilterQuery(query *bun.SelectQuery, params api.GetWarscrollsParams) (*bun.SelectQuery, error) { +func (r *repository) warscrollFilterQuery(query *bun.SelectQuery, params api.GetWarscrollsParams) (*bun.SelectQuery, error) { if params.Name != nil { query = query.Where("? LIKE ?", bun.Ident("name"), *params.Name+"%") } @@ -31,7 +31,7 @@ func (r *warhammerRepository) warscrollFilterQuery(query *bun.SelectQuery, param return query, nil } -func (r *warhammerRepository) GetWarscrolls(ctx context.Context, params api.GetWarscrollsParams) ([]api.Warscroll, error) { +func (r *repository) GetWarscrolls(ctx context.Context, params api.GetWarscrollsParams) ([]api.Warscroll, error) { var warscrolls []api.Warscroll query, err := r.warscrollFilterQuery(r.db.NewSelect().Model(&warscrolls), params) @@ -47,7 +47,7 @@ func (r *warhammerRepository) GetWarscrolls(ctx context.Context, params api.GetW return warscrolls, nil } -func (r *warhammerRepository) GetWarscrollByID(ctx context.Context, id string) (*api.Warscroll, error) { +func (r *repository) GetWarscrollByID(ctx context.Context, id string) (*api.Warscroll, error) { var warscroll api.Warscroll err := r.db.NewSelect().Model(&warscroll).Where("id = ?", id).Scan(ctx) diff --git a/web/index.html b/web/index.html index 8f46d19..773c583 100644 --- a/web/index.html +++ b/web/index.html @@ -3,7 +3,7 @@ - Warhammer Age of Sigmar API (Unofficial) + AoS API (Unofficial)