Macaron Documentation
  • Welcome
  • Starter Guide
  • Core Concepts
  • Core Services
  • Custom Services
  • Middlewares
    • Routing
    • Templating
    • Gzip
    • Localization
    • Data Binding and Validation
    • Cache
    • Captcha
    • Session
    • Cross-Site Request Forgery
    • Embed Binary Data
    • Serving Multiple Sites
  • FAQs
  • 简体中文
    • 初学者指南
    • 核心概念
    • 核心服务
    • 自定义服务
    • 中间件和辅助模块
      • 路由模块
      • 模板引擎
      • Gzip 压缩
      • 应用本地化
      • 数据绑定与验证
      • 缓存管理(Cache)
      • 验证码服务
      • 会话管理(Session)
      • 跨域请求攻击(CSRF)
      • 嵌入二进制数据
      • 服务多个站点
    • 常见问题
Powered by GitBook
On this page
  • How do I integrate with existing servers?
  • How do I change the port/host?
  • How do I graceful shutdown?
  • How do I pass data in request-level other than service inject?
  • What's the idea behind this other than Martini?
  • Why Logo is a dragon?
  • Live code reload?

Was this helpful?

FAQs

PreviousServing Multiple SitesNext简体中文

Last updated 5 years ago

Was this helpful?

How do I integrate with existing servers?

Every Macaron implements , so it can easily be used to serve subtrees on existing Go servers. For example this is a working Macaron app for Google App Engine:

package hello

import (
    "net/http"

    "gopkg.in/macaron.v1"
)

func init() {
    m := macaron.Classic()
    m.Get("/", func() string {
        return "Hello world!"
    })
    http.Handle("/", m)
}

How do I change the port/host?

m := macaron.Classic()
// ...
log.Fatal(http.ListenAndServe(":8080", m))

Or following ways:

  • m.Run("0.0.0.0"), listen on 0.0.0.0:4000

  • m.Run(8080), listen on 0.0.0.0:8080

  • m.Run("0.0.0.0", 8080), listen on 0.0.0.0:8080

How do I graceful shutdown?

package main

import (
    ...
    "net/http"

    "gopkg.in/macaron.v1"
    "gopkg.in/tylerb/graceful.v1"
)

func main() {
    m := macaron.Classic()

    ...

    mux := http.NewServeMux()
    mux.Handle("/", m)
    graceful.Run(":4000", 60*time.Second, mux)
}

How do I pass data in request-level other than service inject?

What's the idea behind this other than Martini?

  • Integrate frequently used middlewares and helper methods with less reflection.

  • Replace default router with faster multi-tree router.

  • Make a deep source study against Martini.

Why Logo is a dragon?

Shouldn't it be some sort of dessert?

The transliteration of Macaron in Chinese is Maca Long, Long means dragon, so actually the Logo is a dragon whose name is Maca. Hah!

Live code reload?

Macaron's Run function looks for the PORT and HOST environment variables and uses those. Otherwise Macaron will default to . To have more flexibility over port and host, use the function instead.

There is a field called Data with type map[string]interface{} in where you can store and retrieve any type of data. It comes with so every request is independent.

See example .

Make it much easier to power project.

is the prefect fit for live reloading Macaron and other apps.

localhost:4000
http.ListenAndServe
*macaron.Context
*macaron.Context
here
Gogs
Bra
http.Handler
instance