Skip to content
@go-gorf

Golang Rest Framework

Golang Rest Framework (Gorf)

Build Status

Django inspired Rest Framework for Golang.

Vision

Introducing Gorf, the Golang REST API framework that empowers developers to easily create and reuse modular apps. Inspired by the simplicity and flexibility of Python Django, Gorf utilizes the full MVC architecture, providing dedicated model, URL, and view files for effortless understanding. Gorf's plug and play app concept enables infinite scalability and customization, making Gorf the go-to solution for anyone looking to kickstart a new project in Golang. Join our community and contribute your ideas and innovations to build a framework that streamlines the development process for all.

Features

  • Generic
  • Simplicity
  • Based on known architecture
  • Reusability
  • Support for apps
  • Custom database backends
  • More feature work in progress

Installation

go get github.com/go-gorf/gorf

Install gorf auth app

go get github.com/go-gorf/auth

Tutorial

Firstly, Create a new main package with following code

package main

import (
	"log"
)

func main() {
	r := BootstrapRouter()
	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")
}

settings.go

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/auth"
	"github.com/go-gorf/gorf"
)

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

func LoadSettings() {
	// jwt secret key
	gorf.Settings.SecretKey = "GOo8Rs8ht7qdxv6uUAjkQuopRGnql2zWJu08YleBx6pEv0cQ09a"
	gorf.Settings.DbConf = &gorf.SqliteBackend{
		Name: "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
}

Write your own apps

Create a new package named "hello"

add app.go file

package hello

import (
	"github.com/go-gorf/gorf"
)

func setup() error {
	// Add setup here
	return nil
}

var HelloApp = gorf.GorfBaseApp{
	Name:         "Hello",
	RouteHandler: Urls,
	SetUpHandler: setup,
}

add urls.go file

package hello

import "github.com/gin-gonic/gin"

func Urls(r *gin.Engine) {
	r.POST("/hello", Hello)
}

add views.go file

package hello

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func Hello(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{
		"message": "Hello world",
	})
}

Check the Gorf project template

https://github.com/go-gorf/template

Pinned Loading

  1. gorf gorf Public

    Django inspired Golang Rest Framework

    Go 22

  2. auth auth Public

    gorf auth app

    Go 2

Repositories

Showing 8 of 8 repositories
  • go-gorf.github.io Public

    gorf docs

    go-gorf/go-gorf.github.io’s past year of commit activity
    0 MIT 0 0 0 Updated Sep 9, 2023
  • gorf Public

    Django inspired Golang Rest Framework

    go-gorf/gorf’s past year of commit activity
    Go 22 MIT 0 2 0 Updated Sep 9, 2023
  • .github Public
    go-gorf/.github’s past year of commit activity
    0 MIT 0 0 0 Updated Sep 9, 2023
  • auth Public

    gorf auth app

    go-gorf/auth’s past year of commit activity
    Go 2 MIT 0 2 1 Updated Jun 20, 2023
  • admin Public

    Gorf Admin

    go-gorf/admin’s past year of commit activity
    HTML 0 MIT 0 1 1 Updated Jun 8, 2023
  • gorf-cli Public

    A command line tool for Golang Rest Framework (Gorf)

    go-gorf/gorf-cli’s past year of commit activity
    Go 2 0 1 1 Updated Jun 8, 2023
  • template-app Public

    Gorf App Template

    go-gorf/template-app’s past year of commit activity
    Go 0 0 0 0 Updated May 15, 2023
  • template Public

    gorf template project

    go-gorf/template’s past year of commit activity
    Go 2 MIT 0 0 0 Updated May 14, 2023

Top languages

Go HTML

Most used topics

Loading…