Categorygithub.com/akrck02/valhalla-api-common
modulepackage
0.0.12-20240805110526-dev
Repository: https://github.com/akrck02/valhalla-api-common.git
Documentation: pkg.go.dev

# README

Valhalla api common

This library makes API creation easier creating a faster way to declare endpoints, middleware support, env file support for api properties and creating a standard for each response.

Middleware

Middleware can be added to the HTTP request to perform checks and tranform data. Currently the following modules are added by default:

ModuleAction
✉️RequestGet HTTP request data and store it in context
🔐SecurityCheck security and authoritation for HTTP requests, also fills current User
💾DatabaseCreate and store the database connection to the context if necessary
📈TrazabilityStore endpoint and launcher data inside context
ChecksExecute the custom endpoint checks and return an error if exists
📨ResponseCreate a standard response object if in json format if needed

Info

Every API using api-common library will open by default an endpoint called /info that returns the current info of the APIs, as well as the license, api version and go version

{
    "response": {
        "version": "v1",
        "license": "GNU GPLv3",
        "maintainers": [
            "akrck02",
            "Itros97"
        ],
        "copyleft": "2024",
        "repository": "",
        "go-version": "go1.22.3"
    },
    "response_time": 8646
}

Configuration

The base configuration for the APIs is the following .env

# API common data
IP=0.0.0.0
PORT=2000
VERSION=v1
API_NAME=common
ENV=release
SECRET=527a54f6-eaf2-418a-a679-6d9efdcabb8c

# Mongo database configuration
MONGO_USER=admin
MONGO_PASSWORD=p4ssw0rd
MONGO_SERVER=172.20.0.30
MONGO_PORT=27017

# CORS configuration
CORS_ORIGIN=*
CORS_METHODS=GET,POST,PUT,PATCH,OPTIONS,DELETE
CORS_HEADERS=Content-Type,Authorization
CORS_MAX_AGE=3600

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author

# Variables

ApiMiddlewares is a list of middleware functions that will be applied to all API requests this list can be modified to add or remove middlewares the order of the middlewares is important, it will be applied in the order they are listed.