forge

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 19 Imported by: 0

README

WIP

🔥 Forge

A Go library/tool for building backend for fullstack apps.

Usage

Forge can be used either directly as a tool or as a library.

As a tool
  1. Download & unpack a Go release from releases section.
  2. Tune the forge.yml file as per your needs.
  3. Run ./forge serve -c forge.yml

If you have frontend build, use --static=./ui to serve as static files.

As a library [Goal]
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/spy16/forge"
	"github.com/spy16/forge/builtins/firebase"
	"github.com/spy16/forge/core"
)

func main() {
	cli := forge.CLI("myapp",
		forge.WithAuth(&firebase.Auth{
			ProjectID: "foo",
		}),
		forge.WithPostHook(func(app core.App, conf core.ConfigLoader) error {
			r := app.Chi()
			r.Use(app.Authenticate())
			r.Get("/api/my-endpoint", func(w http.ResponseWriter, r *http.Request) {
				// Only accessible with firebase auth token
            })
			return nil
		}),
	)
	_ = cli.Execute()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLI added in v0.1.1

func CLI(name string, forgeOpts ...Option) *cobra.Command

CLI returns a new Cobra CLI that can be used directly.

func Forge

func Forge(ctx context.Context, name string, opts ...Option) (chi.Router, error)

Forge initialises a new app instance from the given options. All modules will be initialised, all routes will be setup and a fiber app instance ready-for-use will be returned.

Types

type Hook added in v0.1.1

type Hook func(core.App, core.ConfLoader) error

Hook can be used with to further customise an app instance.

type Option

type Option func(app *forgedApp) error

Option values can be used to customise the forging process.

func WithAuth added in v0.1.1

func WithAuth(auth core.Auth) Option

WithAuth sets a custom core.Auth implementation to be used.

func WithConfLoader added in v0.1.1

func WithConfLoader(cnfL core.ConfLoader) Option

WithConfLoader sets a custom core.ConfLoader implementation.

func WithPostHook added in v0.1.1

func WithPostHook(hook Hook) Option

WithPostHook will set a hook that will be invoked when the app is fully initialised. This hook can be used to set up custom routes, etc.

func WithUserRegistry added in v0.1.1

func WithUserRegistry(reg core.UserRegistry) Option

WithUserRegistry sets a custom user registry to be used.

Directories

Path Synopsis
builtins
cmd
forge command
log

Jump to

Keyboard shortcuts

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