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.

Comments
  • Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.16

    Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.16

    Bumps github.com/uptrace/bunrouter from 1.0.14 to 1.0.16.

    Release notes

    Sourced from github.com/uptrace/bunrouter's releases.

    v1.0.16

    Please refer to CHANGELOG.md for details

    v1.0.15

    Please refer to CHANGELOG.md for details

    Changelog

    Sourced from github.com/uptrace/bunrouter's changelog.

    1.0.16 (2022-05-23)

    Bug Fixes

    • fix extracting params from routes with wildcard and named params (2741aad)

    Features

    1.0.15 (2022-05-08)

    Bug Fixes

    • call method not allowed handler once (37425b7)
    Commits
    • 4f96006 chore: release v1.0.16 (release.sh)
    • 8b211ea chore: go mod tidy
    • 2741aad fix: fix extracting params from routes with wildcard and named params
    • b2d6582 feat(reqlog): add trace id
    • 77f7d48 Merge pull request #69 from uptrace/release/v1.0.15
    • 5a756ad chore: release v1.0.15 (release.sh)
    • 37425b7 fix: call method not allowed handler once
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.15

    Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.15

    Bumps github.com/uptrace/bunrouter from 1.0.14 to 1.0.15.

    Release notes

    Sourced from github.com/uptrace/bunrouter's releases.

    v1.0.15

    Please refer to CHANGELOG.md for details

    Changelog

    Sourced from github.com/uptrace/bunrouter's changelog.

    1.0.15 (2022-05-08)

    Bug Fixes

    • call method not allowed handler once (37425b7)
    Commits
    • 77f7d48 Merge pull request #69 from uptrace/release/v1.0.15
    • 5a756ad chore: release v1.0.15 (release.sh)
    • 37425b7 fix: call method not allowed handler once
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Add helper methods for easier default router usage

    Add helper methods for easier default router usage

    This PR adds a couple of helper methods to simplify using the router.

    Instead of mojito.DefaultRouter().GET("/", handleRoot) you can now just do mojito.GET("/", handleRoot). The same works for every router method (DELETE, GET, WithGroup, WithMiddleware, etc.) as well as for the ListenAndServe method, so now it is possible to do mojito.ListenAndServe(":8080).

  • Bump github.com/uptrace/bun from 1.1.3 to 1.1.4

    Bump github.com/uptrace/bun from 1.1.3 to 1.1.4

    Bumps github.com/uptrace/bun from 1.1.3 to 1.1.4.

    Release notes

    Sourced from github.com/uptrace/bun's releases.

    v1.1.4

    Please refer to CHANGELOG.md for details

    Changelog

    Sourced from github.com/uptrace/bun's changelog.

    1.1.4 (2022-04-20)

    Bug Fixes

    • automatically set nullzero when there is default:value option (72c44ae)
    • fix ForceDelete on live/undeleted rows (1a33250)
    • fix OmitZero and value overriding (087ea07)
    • rename Query to QueryBuilder (98d111b)

    Features

    • add ApplyQueryBuilder (582eca0)
    • config.go: add connect_timeout to DSN parsable params (998b04d), closes #505
    Commits
    • 78c14c8 Merge pull request #518 from uptrace/release/v1.1.4
    • df90cfe chore: release v1.1.4 (release.sh)
    • 8c60434 chore: fix build
    • d4c3bf9 Merge pull request #517 from uptrace/fix/value-override-omitzero
    • f010b1d Merge pull request #516 from uptrace/fix/soft-delete-force
    • 087ea07 fix: fix OmitZero and value overriding
    • 5b63742 Merge pull request #515 from uptrace/fix/default-null-zero
    • 1a33250 fix: fix ForceDelete on live/undeleted rows
    • 72c44ae fix: automatically set nullzero when there is default:value option
    • 289cc63 Merge branch 'master' of github.com:uptrace/bun
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/golobby/container/v3 from 3.1.7 to 3.2.1

    Bump github.com/golobby/container/v3 from 3.1.7 to 3.2.1

    Bumps github.com/golobby/container/v3 from 3.1.7 to 3.2.1.

    Release notes

    Sourced from github.com/golobby/container/v3's releases.

    v3.2.1

    Fix container.Call returning nil error

    v3.2.0

    Add Must helpers Support error in call receivers Some code improvements

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Support for Stdlib Handlers and Middleware

    Support for Stdlib Handlers and Middleware

    This PR will add stdlib compatibility to mojito handlers. You will be able to mix and match mojito and stdlib middleware, as well as handlers.

    For example:

    Request -> stdlib middleware -> mojito middleware -> stdlib handler Request -> stdlib middleware -> mojito middleware -> mojito handler Request -> stdlib middleware -> stdlib middleware -> stdlib handler

    This allows you to reuse existing handlers and middleware, without any conversion hassle.

  • Bump github.com/uptrace/bunrouter from 1.0.13 to 1.0.14

    Bump github.com/uptrace/bunrouter from 1.0.13 to 1.0.14

    Bumps github.com/uptrace/bunrouter from 1.0.13 to 1.0.14.

    Release notes

    Sourced from github.com/uptrace/bunrouter's releases.

    v1.0.14

    Please refer to CHANGELOG.md for details

    Changelog

    Sourced from github.com/uptrace/bunrouter's changelog.

    1.0.14 (2022-04-14)

    Bug Fixes

    • use httpsnoop to wrap response writer (3d86932)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/golobby/container/v3 from 3.1.6 to 3.1.7

    Bump github.com/golobby/container/v3 from 3.1.6 to 3.1.7

    Bumps github.com/golobby/container/v3 from 3.1.6 to 3.1.7.

    Release notes

    Sourced from github.com/golobby/container/v3's releases.

    v3.1.7

    Fix issue #37 (Single with error causes running the body twice)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/rs/zerolog from 1.26.1 to 1.27.0

    Bump github.com/rs/zerolog from 1.26.1 to 1.27.0

    Bumps github.com/rs/zerolog from 1.26.1 to 1.27.0.

    Commits
    • e9344a8 docs: add an example for Lshortfile-like implementation of CallerMarshalFunc ...
    • 263b0bd #411 Add FieldsExclude parameter to console writer (#418)
    • 588a61c ctx: Modify WithContext to use a non-pointer receiver (#409)
    • 361cdf6 Remove extra space in console when there is no message (#413)
    • fc26014 MsgFunc function added to Event (#406)
    • 025f9f1 journald: don't call Enabled before each write (#407)
    • 3efdd82 call done function when logger is disabled (#393)
    • c0c2e11 Consistent casing, redundancy, and spelling/grammar (#391)
    • 665519c Fix ConsoleWriter color on Windows (#390)
    • 0c8d3c0 move the lint command to its own package (#389)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.17

    Bump github.com/uptrace/bunrouter from 1.0.14 to 1.0.17

    Bumps github.com/uptrace/bunrouter from 1.0.14 to 1.0.17.

    Release notes

    Sourced from github.com/uptrace/bunrouter's releases.

    v1.0.17

    Please refer to CHANGELOG.md for details

    v1.0.16

    Please refer to CHANGELOG.md for details

    v1.0.15

    Please refer to CHANGELOG.md for details

    Changelog

    Sourced from github.com/uptrace/bunrouter's changelog.

    1.0.17 (2022-05-25)

    Bug Fixes

    • fix another corner case with incorrect param resolving (7e3d720)

    1.0.16 (2022-05-23)

    Bug Fixes

    • fix extracting params from routes with wildcard and named params (2741aad)

    Features

    1.0.15 (2022-05-08)

    Bug Fixes

    • call method not allowed handler once (37425b7)
    Commits
    • d468c50 Merge pull request #73 from uptrace/release/v1.0.17
    • 46ae2c7 chore: release v1.0.17 (release.sh)
    • 7e3d720 fix: fix another corner case with incorrect param resolving
    • c22c6d4 Merge pull request #72 from uptrace/release/v1.0.16
    • 4f96006 chore: release v1.0.16 (release.sh)
    • 8b211ea chore: go mod tidy
    • 2741aad fix: fix extracting params from routes with wildcard and named params
    • b2d6582 feat(reqlog): add trace id
    • 77f7d48 Merge pull request #69 from uptrace/release/v1.0.15
    • 5a756ad chore: release v1.0.15 (release.sh)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • [Feature] Automatic form parsing and optional validation

    [Feature] Automatic form parsing and optional validation

    I would like to be able to create a struct defining the data structure of a submitted form that I want to process in a Mojito handler. The data can be in the form of regular x-form-www-urlencoded data, JSON body, (perhaps) XML body or even GET parameters.

⚗ 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

Jun 21, 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

Jan 18, 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.

Apr 13, 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
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
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

Jun 21, 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

Jun 27, 2022
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 <

Jun 23, 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

Jul 3, 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

Jun 30, 2022
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

Jun 7, 2022
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
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