awesome

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 12 Imported by: 0

README

awesome Go codecov

Overview

Awesome is a REST API that stores a Video Library in Mongo Atlas and Mux.com for video ingestion.

Getting started

Requirements
  • github.com/golang/go go1.22
  • github.com/golang-jwt/jwt/v5 v5.2.0
  • github.com/google/uuid v1.6.0
  • github.com/gorilla/mux v1.8.1
  • github.com/muxinc/mux-go/v5 v5.2.0
  • github.com/sirupsen/logrus v1.9.3
  • github.com/stretchr/testify v1.8.4
  • go.mongodb.org/mongo-driverv1.13.1

Test and build

Test the app:

make test

Usage

Install dependencies:

go get github.com/javiertlopez/awesome
Example
package main

import (
	"net/http"
	"os"
	"time"

	"github.com/javiertlopez/awesome"

	"github.com/sirupsen/logrus"
)

const (
	writeTimeout = 15 * time.Second
	readTimeout  = 15 * time.Second
	idleTimeout  = 60 * time.Second
)

var (
	application awesome.App
	commit      string
	version     string
)

func main() {
	// Environment variables
	addr := os.Getenv("ADDR")
	mongoString := os.Getenv("MONGO_STRING")
	muxTokenID := os.Getenv("MUX_TOKEN_ID")
	muxTokenSecret := os.Getenv("MUX_TOKEN_SECRET")
	muxKeyID := os.Getenv("MUX_KEY_ID")
	muxKeySecret := os.Getenv("MUX_KEY_SECRET")

	// Create a logrus logger and set up the output format as JSON
	logger := logrus.New()
	logger.Formatter = &logrus.JSONFormatter{}

	application = awesome.New(
		awesome.AppConfig{
			Commit:         commit,
			Version:        version,
			MongoDB:        mongoDB,
			MongoURI:       mongoString,
			MuxTokenID:     muxTokenID,
			MuxTokenSecret: muxTokenSecret,
			MuxKeyID:       muxKeyID,
			MuxKeySecret:   muxKeySecret,
		},
		logger,
	)

	// Create a Gorilla Mux router
	router := application.Router()

	// Create a Server instance with the router
	srv := &http.Server{
		Addr:         addr,
		WriteTimeout: writeTimeout,
		ReadTimeout:  readTimeout,
		IdleTimeout:  idleTimeout,
		Handler:      router,
	}

	// Start the server
	logger.Fatal(srv.ListenAndServe())
}

License

Licensed under MIT License. © 2024 Hiram Torres Lopez.

Documentation

Index

Constants

View Source
const (
	Database = "delivery" // Database keeps the database name

)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App holds the handler, and logger

func New

func New(config AppConfig, logger *logrus.Logger) App

New returns an App

func (*App) Router

func (a *App) Router() *mux.Router

Router returns the *mux.Router

type AppConfig

type AppConfig struct {
	Commit         string
	Version        string
	MongoURI       string
	MuxTokenID     string
	MuxTokenSecret string
	MuxKeyID       string
	MuxKeySecret   string
	Test           bool
}

AppConfig struct with configuration variables

Directories

Path Synopsis
repository

Jump to

Keyboard shortcuts

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