Code your next Go web project with (a) Mojito! No matter if its an API or a website, go-mojito assists you with dependency injection, simple routing, custom request / response objects and template rendering

PRs Welcome

Go-Mojito is a super-modular library to bootstrap your next Go web project. It can be used for strict API-only purposes as well as server-side rendering.

SonarCloud Report


Features

Dependency InjectionRoutingTemplatingLoggingMiddlewareCachingREST Router (beta)

Documentation

Read our GitHub Wiki, check out the Example Project or try run the code below

Icon made with Gopherize and flaticon.


package main

import (
	"github.com/infinytum/go-mojito"
)

var (
	address  = "0.0.0.0:8123"
	cacheKey = "greeting"

	Logger mojito.Logger
	Router mojito.Router
)

func main() {
	Logger = mojito.DefaultLogger()
	Router = mojito.DefaultRouter()

	Logger.Info("Registering application routes...")
	Router.Group("/hello", func(router mojito.Routeable) {
		router.GET("", helloHandler)
		router.GET("/:name", setHelloHandler)
	})

	Logger.Infof("Server has started on %s", address)
	Logger.Error(Router.ListenAndServe(address))
}

type HelloContext struct {
	Cache mojito.Cache `container:"type"`
}

func helloHandler(ctx HelloContext, res *mojito.Response, req *mojito.Request) {
	var name string
	ctx.Cache.GetOrDefault(cacheKey, &name, "world")
	res.String("Hello " + name + "!")
}

func setHelloHandler(ctx HelloContext, res *mojito.Response, req *mojito.Request) {
	var newName = req.ParamOrDefault("name", "world")
	Logger.Field("name", newName).Infof("A new name to greet has been set.")
	ctx.Cache.Set(cacheKey, newName)
	res.String("A new name has been set!")
}

How to use this example code

Once you start this quick example code, a webserver will listen on any IP with the port 8123. On https://localhost:8123/hello you will be greeted with "Hello world!" by default.

To change "world" into something else, you can open https://localhost:8123/hello/yourname and now you will be greeted with whatever name you used.

Similar Resources

Wrapper package for Go's template/html to allow for easy file-based template inheritance.

Extemplate Extemplate is a small wrapper package around html/template to allow for easy file-based template inheritance. File: templates/parent.tmpl

Dec 6, 2022

Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

quicktemplate A fast, powerful, yet easy to use template engine for Go. Inspired by the Mako templates philosophy. Features Extremely fast. Templates

Dec 26, 2022

A sane and simple Go REST API template.

Gosane 🧘‍♀️ A sane and simple Go REST API template. Clone me and edit me to fit your usecase. What is Gosane? Gosane is a cloneable API template to g

Dec 7, 2022

A simple template using Fiber for me to bootstrap API services quickly.

Fiber Template A simple template using Fiber for me to bootstrap API services quickly. Features Fiber GORM air for hot reloading ... and possibly more

Dec 16, 2021

Clean arch Golang template project

Template No previous versions, still working on this one to reach v1. API Service for pssword app mobilde based on : https://github.com/bxcodec/go-cle

Sep 15, 2021

go project template

go project template

go-project-template Install go get github.com/chyroc/go-project-template Usage package main import ( "fmt" "github.com/chyroc/go-project-template"

Oct 6, 2021

This my project template for making fiber with SSR taste by empowered mustache engine.

SSR-FIBER-TEMPLATE This my project template for making fiber with SSR taste by empowered mustache engine. Folder Hierarchy Name Description configs Co

May 9, 2022

Temporal Go Project Template

 Temporal Go Project Template

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

Dec 7, 2021

Standup a new website in 2 commands.

Standup a new website in 2 commands.

Page CLI Getting Started Download latest release for your operating system. Install by unzipping it and moving the file to a directory included in you

Nov 18, 2022
⚗ The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.
⚗ The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.

cli-template ✨ ⚗ A template for beautiful, modern, cross-platform compatible CLI tools written with Go! Getting Started | Wiki This template features

Dec 4, 2022
Go-api-template - A rough template to give you a starting point for your API

Golang API Template This is only a rough template to give you a starting point f

Jan 14, 2022
Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

Oct 25, 2022
Allows you to fill in variables in your custom project templates.

go-templater The best project templater go-templater lets you use any project template you want and replace the variables with values from the config.

Nov 6, 2021
Fusozay Var Var: A CLI tool for quick text template rendering

fvv - Fusozay Var Var A CLI tool for quick text template rendering Fusozay Var Var means "have fun" It is a reference to something I see a lot Fusozay

Dec 11, 2021
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Dec 5, 2022
Template for depency injection in golang (no libraries)

Go Dependency Injection (No libraries) Project template based on the most common layered architecture style, made to explain how to do dependency inje

Mar 30, 2022
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

Dec 25, 2022
A template to build dynamic web apps quickly using Go, html/template and javascript
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Dec 29, 2022
Made from template temporalio/money-transfer-project-template-go
Made from template temporalio/money-transfer-project-template-go

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

Jan 6, 2022