gorf

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 5 Imported by: 6

README

gorf

Go

Django inspired Golang Rest Framework

Installation

Install gorf

go get github.com/go-gorf/gorf

Install gorf auth app

go get github.com/go-gorf/auth

Quickstart

Firstly, Create a new main package with following code

package main

import (
	"log"

	"github.com/go-gorf/gorf"
	"github.com/go-gorf/gorf-contrib/auth"
)

func main() {
	r := BootstrapRouter()
	user := auth.User{}
	println(user.Email)
	err := r.Run()
	if err != nil {
		log.Fatal("Unable to create the gin server")
	} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

Next, Create a settings.go file in the main package with the following code snippet

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/go-gorf/gorf"
	"github.com/go-gorf/auth"
)

// add all the apps
var apps = []gorf.GorfApp{
	&auth.AuthApp,
}

func LoadSettings() {
	// jwt secret key
	Settings.SecretKey = "GOo8Rs8ht7qdxv6uUAjkQuopRGnql2zWJu08YleBx6pEv0cQ09a"
	Settings.DbConf = &SqliteBackend{
		"db.sqlite",
	}
}

// bootstrap server
func BootstrapRouter() *gin.Engine {
	gorf.Apps = append(apps)
	LoadSettings()
	gorf.InitializeDatabase()
	gorf.SetupApps()
	r := gin.Default()
	gorf.RegisterApps(r)
	return r
}

Project Management Board

https://github.com/orgs/go-gorf/projects/1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Apps []GorfApp

array of all registerd apps

View Source
var DB *gorm.DB
View Source
var Settings = GlobalSettings{
	UserObjKey: "user",
	UserObjId:  "id",
	DbConf:     &SqliteBackend{Name: "data.db"},
}

Functions

func InitializeDatabase

func InitializeDatabase()

func RegisterApps

func RegisterApps(r *gin.Engine)

Register apps

func SetupApps

func SetupApps()

Setup all apps

Types

type DatabaseBackend added in v0.0.3

type DatabaseBackend interface {
	Connect() error
	Close() error
}

type GlobalSettings

type GlobalSettings struct {
	SecretKey  string
	UserObjKey string
	UserObjId  string
	DbConf     DatabaseBackend
}

Global Project settings

type GorfApp

type GorfApp interface {
	Setup()
	Register(r *gin.Engine)
}

Gorp App interface

type PostgrSQLBackend added in v0.0.3

type PostgrSQLBackend struct {
	Dsn string
}

func (*PostgrSQLBackend) Close added in v0.0.3

func (backend *PostgrSQLBackend) Close() error

func (*PostgrSQLBackend) Connect added in v0.0.3

func (backend *PostgrSQLBackend) Connect() error

type SqliteBackend added in v0.0.3

type SqliteBackend struct {
	Name string
}

func (*SqliteBackend) Close added in v0.0.3

func (backend *SqliteBackend) Close() error

func (*SqliteBackend) Connect added in v0.0.3

func (backend *SqliteBackend) Connect() error

Directories

Path Synopsis
backends
dynamodbi module
gormi module
common module

Jump to

Keyboard shortcuts

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