Skip to content

Latest commit

 

History

History
134 lines (89 loc) · 2.04 KB

README.md

File metadata and controls

134 lines (89 loc) · 2.04 KB

godzilla

forthebadge

About:

  • A powerfull go web framework
  • Fast 🚀
  • Secure 🔒
  • Easy Peasy :)

Features:

  • Log Middleware

Installation:

go get -u github.com/godzillaframework/godzilla

Examples:

  • a simple api
package main

import "github.com/godzillaframework/godzilla"

func main() {
	gz := godzilla.New()

	gz.Get("/index", func(ctx godzilla.Context) {
		ctx.SendString("Hello EveryOne!!!")
	})

	gz.Start(":9090")
}
  • params
package main

import "github.com/godzillaframework/godzilla"

func main() {
    gz := godzilla.New()

    gz.Get("/users/:user", func(ctx godzilla.Context) {
        ctx.SendString(ctx.Param("user"))
    })

    gz.Start(":8080")
}
  • static files
package main

import "github.com/godzillaframework/godzilla"

func main() {
    gz := godzilla.New()

    gz.Static("/imgs", "./images")

    /* go to localhost:8080/imgs/image.png */

    gz.Start(":8080")
}

middleware:

  • Log middleware:
package main

import (
	"log"

	"github.com/godzillaframework/godzilla"
)

func main() {
	gz := godzilla.New()
	
	logMiddleware := func(ctx godzilla.Context) {
		log.Printf("log message!")

		ctx.Next()
	}
	
	gz.Use(logMiddleware)
	
	gz.Start(":8080")
  • Unauthorized middleware:
package main

import (
	"log"

	"github.com/godzillaframework/godzilla"
)

func main() {

	gz := godzilla.New()

	unAuthorizedMiddleware := func(ctx godzilla.Context) {
		ctx.Status(godzilla.StatusUnauthorized).SendString("You are unauthorized to access this page!")
	}

	gz.Get("/hello", func(ctx godzilla.Context) {
		ctx.SendString("Hello World!")
	})

	gz.Get("/protected", unAuthorizedMiddleware, func(ctx godzilla.Context) {
		ctx.SendString("You accessed a protected page")
	})


	gz.Start(":8080")
}
  • example app

  • for more tutorials visit the docs