Socket
Socket
Sign inDemoInstall

github.com/novatrixtech/mercurius

Package Overview
Dependencies
22
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/novatrixtech/mercurius

Mercurius gives you speed when create 'Go' applications. It lets you being focused at business. Get a Go web application template with: Internationalization, Routers, Logging, Cache, Database, Jade Template Render Engine, JWT, oAuth 2.0. Built upon Macaron, all those items are all configured and ready to use. " " " "


Version published

Readme

Source

Mercurius

GoDoc license

Mercurius gives you speed to create new Go (golang) web applications and/or microservices. The most Go Web Applications' Scaffolding popular tool to let you to be more focused on your business than in your backend.

Get a Go (golang) web application and/or microservice template that includes: Internationalization, Routers, Logging, Cache, Database, Jade/Pug Template Render Engine, JWT, oAuth 2.0, Prometheus and Docker. Built on top of Macaron, all items are configured and ready to use.

Getting Started

go get -v github.com/novatrixtech/mercurius/...

or

go get -u github.com/novatrixtech/mercurius

go install github.com/novatrixtech/mercurius

cd $GOPATH or for Windows users cd %GOPATH%

mercurius new

IMPORTANT:

Mercurius must be called from developer's GOPATH/src dir

Structure of a Project

/conf
Application configuration including environment-specific configs

/conf/app
Middlewares and routes configuration

/handler
HTTP handlers

/locale
Language specific content bundles

/lib
Common libraries to be used across your app

/model
Models

/public
Web resources that are publicly available

/public/templates
Jade templates or Native templates

/repository
Database comunication following repository pattern

main.go
Application entry

Creating routes

Setup all your routes inside the SetupRoutes func in conf/app/app.go

func SetupRoutes(app *macaron.Macaron) {
	app.Group("", func() {
		app.Get("/", handler.ListAccessPage)
	}, auth.LoginRequired)
	app.Get("/login", handler.LoginPage)
	app.Post("/login", binding.BindIgnErr(model.Login), handler.BasicAuth)
}

Creating handlers for the routers

Put all handler files inside the handler folder

  • Handle raw text
func Hello() string {
        return "Hello"
}
  • Handle JSON
import (
        "net/http"
        "{{.AppPath}}/lib/contx"
)

func User(ctx *contx.Context) {
	//user is the struct you want to return
        ctx.JSON(http.StatusOk, user)
}
  • Handle XML
import (
        "net/http"
        "{{.AppPath}}/lib/contx"
)

func User(ctx *contx.Context) {
	//user is the struct you want to return
        ctx.XML(http.StatusOk, user)
}
  • Handle Jade HTML Template Engine

The extension of the templates must be .jade. Put the jade files inside public/templates folder

import (
        "net/http"
        "{{.AppPath}}/lib/contx"
)

func User(ctx *contx.Context) {
	//edit is the page name you want to render
        ctx.HTML(http.StatusOk, "edit")
}
  • Handle Go HTML Template Engine

The extension of the templates must be .tmpl or .html. Put the Go template files inside public/templates folder

import (
        "net/http"
        "{{.AppPath}}/lib/contx"
)

func User(ctx *contx.Context) {
	//edit is the page name you want to render
        ctx.NativeHTML(http.StatusOk, "edit")
}

To deploy only the binary file

Besides binary file you need to copy locale, conf and public directories along with it in order to a Mercurius project works properly.

Get more details

Check out our Sample Project at Example folder to get more information about a Mercurius implementation.

FAQs

Last updated on 17 Sep 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc