Code Monkey home page Code Monkey logo

samp-objects-api's Introduction

SA:MP Objects API Service

https://samp-objects.com is a service I built for the San Andreas Multiplayer community - SA:MP 0.3.8 added the ability for servers to provide custom assets to clients so this website is a platform where users can share their work and server owners can search for content to add to their servers.

Architecture

The site follows a modern, decoupled RESTful service-oriented architecture. The frontend is a React app and you can check that out here.

The routes are declared in router.go which maps routes to their respective functions. Routes are organised into versions, then namespaces then individual collections - a pretty standard RESTful model. accounts.go contains functions for /v0/accounts/ etc. There are also sub-packages for other isolated components:

  • storage provides an interface for persistent storage, the current database of choice is MongoDB and the file store is S3-based and uses the Minio client.
  • types provides common type declarations for structures such as users and objects.

Authentication

Gorilla is the stack of choice here, it's used for route multiplexing, session state, CSRF tokens and CORS middleware.

Routing is declarative, Authenticated: true results in the app.Authenticated middleware being applied to a route. This implements JWT authentication (which was implemented early on) and Gorilla Secure Session which was added later on top of JWT and is used to store a user ID with requests to know which user sent each request.

Development

My personal environment makes heavy use of Docker to provide local services such as databases. If your environment does not have Docker available, you'll have to set your own databases up.

To spin up a local MongoDB and Minio with very simple credentials (do not do this on a production server!) simply run:

make mongodb && make minio

MongoDB has no password and Minio uses default and 12345678 as the access and secret key.

To fire up a local instance (non containerised) instance of the server, run:

make local

And to fire up a container, run:

make run

For a production deployment, make sure .env contains all the production credentials (I am still working on a better way of handling secrets in production!) and run:

make run-prod

Check the makefile for other commands.

Tests

The routing does not have full test coverage yet (it might do in the future, and chances are I'll forget to update this readme when it does!) however the storage package does.

Contributing

I welcome contributions, make sure you follow Go standards (gofmt etc) and run static analysis on your code to ensure quality.

samp-objects-api's People

Contributors

southclaws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

samp-objects-api's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.