core

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 12 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 as framework modular, or your own config with manual use of package, or event use directly enhanced package.

  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"
Modular Framework example

On your main.go initialize every package before, and inject to ModuleParams:

//...
captcha := true
privateKeyPath := "./key_private.pem"
publicKeyPath := "./key_public.pem"
core.NewHttp(core.Options{
    EnvPath:        "./.env",
    AuthType:       gin.AuthTypeJwt,
    // if AuthTypeJwt is AuthTypeJwt you need to generate rsa key
    PrivateKeyPath: &privateKeyPath,
    PublicKeyPath:  &publicKeyPath,
    // if AuthType type is AuthTypeGrpc
    // AuthUrl         localhost:50051
    I18n:           bI18n,
    Captcha:        &captcha,
    Modules:        []func(...interface{}){module1.NewHttpV1},
    ModuleParams:   append(make([]interface{}, 0), param1, param2, ...),
})
Core config with manual use of package example
  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:
//...
captcha := true
g := gin.New(&gin.Options{
    I18n:     bI18n,
    Mode:     cfg.HTTP.Mode,
    Version:  cfg.App.Version,
    BaseUrl:  cfg.App.Name,
    Log:      log,
    AuthType: gin.AuthTypeJwt,
    // if AuthType type is AuthTypeJwt
    Jwt: jwt,
    // if AuthType type is AuthTypeGrpc
    // AuthService:  &cfg.Services[0].Url,
    Captcha: &captcha,
})
//...

Enhanced Packages

Commands

Here are some useful commands for executing example usage:

  • cd example/manual && go run cmd/http/main.go
  • cd example/manual && go run cmd/grpc/main.go
  • cd example/modular && go run cmd/http/main.go
  • go install github.com/swaggo/swag/cmd/swag@latest
  • cd example/manual/cmd/http && swag init -o ../../docs
  • cd example/modular/cmd/http && swag init -o ../../docs

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

func NewHttp added in v1.4.0

func NewHttp(o Options)

Types

type Options added in v1.4.0

type Options struct {
	Config         config.Config
	Log            logger.Interface
	AuthType       string
	AuthUrl        *string
	PrivateKeyPath *string
	PublicKeyPath  *string
	I18n           *i18n.Bundle
	Captcha        *bool
	Modules        []func([]interface{})
	ModuleParams   []interface{}
}

Directories

Path Synopsis
auth
example
manual/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
modular/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