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

Overview

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.

You might also like...
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

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

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

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

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

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"

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

 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

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

Releases(v1.3.5)
⚗ 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

null 46 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

Only Tunes Radio 3 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

KyberNetwork 4 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.

null 0 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

Amelia Aronsohn 0 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.

Nelo Mitranim 5 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

Yael 2 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

foolin 314 Dec 25, 2022
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

Adnaan Badr 85 Dec 29, 2022
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

MarkGorewicz 0 Jan 6, 2022