aos

package module
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 4 Imported by: 0

README ΒΆ

AoS

Go Reference Go Report Card

An unnoficial AoS REST API built with Go and Sqlite.

✨ Try the API (hosted)

⚑ Quick Start (self-hosted)

Get started with docker-compose to seed the database and start the API server.

docker-compose up --build --force-recreate --remove-orphans --detach

or with task

task up

πŸ“– Documentation

API documentation is available in YAML format within the repository. The OpenAPI spec is used to generate the transport logic thanks to goapi-gen.

πŸ—„οΈ Adding or Editing Data

All application data used to seed the database is editable in the 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

To add a new entry to the database, just add a new object to the appropriate yaml fixtures file. In this case, fixtures/alliances.yaml. This processes is the same for all data types.

# fixtures/alliances.yaml
    - model: GrandAlliance
      rows:
        - id: order
          name: Order
          description: The forces of Order strive to bring unity and stability to the Mortal Realms. Composed of various factions, they fight against the forces of Chaos.
+       - id: chaos
+         name: Chaos
+         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.

API Endpoints

The API is read-only

βœ…=Available 🚧=Under Construction

  • βœ… /cities - Get all cities
  • βœ… /cities/{id} - Get a city by ID
  • βœ… /grand-alliances - Get all grand alliances
  • βœ… /grand-alliances/{id} - Get a grand alliance by ID
  • βœ… /grand-strategies/ - Get all grand strategies
  • βœ… /grand-strategies/{id} - Get a grand strategy by ID
  • βœ… /units - Get all units
  • βœ… /units/{id} - Get a unit by ID
  • βœ… /warscrolls/ - Get all warscrolls
  • βœ… /warscrolls/{id} - Get a warscroll by ID
  • βœ… /graphql - GraphQL playground
  • βœ… /query - GraphQL query endpoint

πŸ”Ž Querying

The API supports GraphQL queries. The GraphQL playground is available at /graphql and the query endpoint is available at /query.

Example - Get all units
query {
  units {
    id
    name
    description
    grandAlliance
    points
  }
}
Example - Get all units, filtering for a specific name
query {
  units(filter: { name: "Lord" }) {
    id
    name
    description
    grandAlliance
    points
  }
}

πŸ“¦ Go Client

A Go client is available for the API. More examples are available in the example/ directory.

package main

import (
	"context"
	"net/http"
	"time"

	"github.com/brittonhayes/aos/client"
)

func main() {
	//	Setup a context with a timeout so we're covered in case of a slow response
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	// Create a new http client
	c := client.NewClient(&http.Client{}, "https://aos-api.com/query", nil)

	// Get all allegiances
	resp, err := c.GetAllegiances(ctx, client.AllegianceFilters{})
	if err != nil {
		panic(err)
	}

	// List the allegiances
	for _, a := range resp.Allegiances {
		println(a.Name)
	}
}

πŸ“ˆ Monitoring (self-hosted)

Application observability is instrumented with OpenTelemetry. Telemetry is available in Grafana and Prometheus. Application tracing is powered by Grafana Tempo. All application services are behind Traefik reverse proxy.

When running with docker-compose, the following services are available:

πŸ™‹ FAQ

  • Q: Where is X {unit,alliance,etc}? - A: Waiting for you to add it! See the fixtures/ directory for more information.

Any changes to the data hosted by this repository must respect the licensing rules documented by Games Workshop here Intellectual Property Policy.

We are in no way affiliated with Games Workshop and the Warhammer Age of Sigmar data is the sole property of Games Workshop. We are abiding by their Celebrating the Hobby section of the agreement and not commercializing this data in any way. This API is purely to help allow users to engage with the wonderful world of Warhammer in a programattic way 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 intellectual property guidelines.

For more information, view our Contributing Guidelines.

Contributors

Documentation ΒΆ

Overview ΒΆ

Package aos provides the Repository interface for the AoS REST API and services

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var FIXTURES embed.FS
View Source
var HTML_DOCS []byte
View Source
var HTML_HOME []byte

Functions ΒΆ

This section is empty.

Types ΒΆ

type Repository ΒΆ

type Repository interface {
	GetArmyByID(ctx context.Context, id string) (*api.Army, error)
	GetArmies(ctx context.Context) ([]api.Army, error)

	GetAllegianceByID(ctx context.Context, id string) (*api.Allegiance, error)
	GetAllegiances(ctx context.Context, params *api.GetAllegiancesParams) ([]api.Allegiance, error)

	GetCities(ctx context.Context, params *api.GetCitiesParams) ([]api.City, error)
	GetCityByID(ctx context.Context, id string) (*api.City, error)

	GetGrandAllianceByID(ctx context.Context, id string) (*api.GrandAlliance, error)
	GetGrandAlliances(ctx context.Context) ([]api.GrandAlliance, error)

	GetGrandStrategyByID(ctx context.Context, id string) (*api.GrandStrategy, error)
	GetGrandStrategies(ctx context.Context) ([]api.GrandStrategy, error)

	GetUnitByID(ctx context.Context, id string) (*api.Unit, error)
	GetUnits(ctx context.Context, params *api.GetUnitsParams) ([]api.Unit, error)
	GetAbilitiesForUnitByID(ctx context.Context, id string) ([]api.Ability, error)
	GetWeaponsForUnitByID(ctx context.Context, id string) (*api.WeaponsGroup, error)

	GetWarscrollByID(ctx context.Context, id string) (*api.Warscroll, error)
	GetWarscrolls(ctx context.Context, params *api.GetWarscrollsParams) ([]api.Warscroll, error)

	Init(ctx context.Context) error
	Generate(ctx context.Context, name string) error
	Migrate(ctx context.Context) error
	Lock(ctx context.Context) error
	Unlock(ctx context.Context) error
	Rollback(ctx context.Context) error
	Seed(ctx context.Context, fsys fs.FS, names ...string) error
}

Directories ΒΆ

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
cmd
aos
example
internal
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL