Git Product home page Git Product logo

mercurius's Introduction

mercurius

GoDoc license

Mercurius gives you speed to create new 'Go' applications. It let you more focused on your business than in your backend.

Get a web application template for Golang that includes: Internationalization, Routers, Logging, Cache, Database, Jade Template Render Engine, JWT, oAuth 2.0. Built on top of Macaron, all items are configured and ready to use.

Getting Started

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

go install github.com/novatrixtech/mercurius

mercurius new

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/context"
)

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

func User(ctx *context.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/context"
)

func User(ctx *context.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/context"
)

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

mercurius's People

Contributors

felipeweb avatar jeffprestes avatar vmesel avatar

Watchers

Fabiano Leite avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.