core

package module
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 6 Imported by: 0

README

Go API Core Go Report Card

Based on common API stack, here is a list of enhanced packages to simplify your go (or 'golang') API development.

Contents

Getting started

You have an option, you can use core Config or your own config. Here if you use core Config:

  1. Download core by using:
    $ go get -u github.com/tossaro/go-api-core
  1. Add file .env on your main.go folder, see .env

  2. Import the following package:

import core "github.com/tossaro/go-api-core"
  1. Initial the config in main.go code:
func main() {
    cfg, err := core.NewConfig()
    if err != nil {
        log.Fatal("Config error: %s", err)
    }
    //...
}
  1. Add every package that you need for your API as example gin:
cap := true
// grpcUrl := ":" + cfg.GRPC.Port
g := gin.New(&gin.Options{
    Mode:     cfg.HTTP.Mode,
    Version:  cfg.App.Version,
    BaseUrl:  cfg.App.Name,
    Log:      log,
    AuthType: gin.AuthTypeRedis,
    // if session from redis enable redis & jwt
    Redis: rdb,
    Jwt:   jwt,
    // if session from another grpc service
    // AuthService:  &grpcUrl,
    AccessToken:  cfg.TOKEN.Access,
    RefreshToken: cfg.TOKEN.Refresh,
    Captcha:      &cap,
})

Enhanced Packages

License

The MIT License (MIT)

Copyright © 2022 Hamzah Tossaro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	App struct {
		Name    string
		Version string
	}

	Services []Service

	HTTP struct {
		Mode string
		Port string
	}

	GRPC struct {
		Port string
	}

	Log struct {
		Level string
	}

	Redis struct {
		Url      string
		Password string
	}

	Postgre struct {
		Url     string
		PoolMax int
	}

	TOKEN struct {
		Access  int
		Refresh int
	}
}

func NewConfig

func NewConfig(f string) (Config, logger.Interface)

type Service

type Service struct {
	Url  string
	Name string
}

Directories

Path Synopsis
auth
example
docs
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag

Jump to

Keyboard shortcuts

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