:golf: The Golf web framework

GoDoc License Build Status Build Status Coverage Status

A fast, simple and lightweight micro-web framework for Go, comes with powerful features and has no dependencies other than the Go Standard Library.

Homepage: golf.readme.io

Installation

go get github.com/dinever/golf

Features

  1. No allocation during routing and parameter retrieve.

  2. Dead simple template inheritance with extends and include helper comes out of box.

    layout.html

    <h1>Hello World</h1>
    {{ template "body" }}
    {{ include "sidebar.html" }}

    index.html

    {{ extends "layout.html" }}
    
    {{ define "body"}}
    <p>Main content</p>
    {{ end }}

    sidebar.html

    <p>Sidebar content</p>
  3. Built-in XSRF and Session support.

  4. Powerful middleware chain.

  5. Configuration from JSON file.

Hello World

package main

import "github.com/dinever/golf"

func mainHandler(ctx *golf.Context) {
  ctx.Send("Hello World!")
}

func pageHandler(ctx *golf.Context) {
  ctx.Send("Page: " + ctx.Param("page"))
}

func main() {
  app := golf.New()
  app.Get("/", mainHandler)
  app.Get("/p/:page/", pageHandler)
  app.Run(":9000")
}

The website will be available at http://localhost:9000.

Benchmark

The following chart shows the benchmark performance of Golf compared with others.

Golf benchmark

For more information, please see BENCHMARKING.md

Docs

golf.readme.io/docs

License

MIT License

Comments
  • Use crypto/rand instead of math/rand

    Use crypto/rand instead of math/rand

    randomBytes in xsrf.go uses math.rand to generate CSRF tokens. This is unsafe/insecure, and because it is seeded with time.UnixNano, generates predictable results that would allow an attacker to bypass CSRF protection.

    sessionID in session.go correctly uses crypto/rand to generate a session ID. You should split this code out and re-use it for both session ID generation and CSRF token generation.

    (You're also welcome to import or repurpose https://github.com/gorilla/csrf for this as well, which has some additional mitigations against CSRF bypass)

  • Use crypto/rand for XSRF token generation

    Use crypto/rand for XSRF token generation

    Issue: #20

    Uses crypto/rand instead of math/rand for XSRF token generation, as @elithrar suggested. In that issue it was also suggested that we either use gorilla/csrf or repurpose it for Golf, so this PR may not close the issue.

  • Why default redirect is use 301?

    Why default redirect is use 301?

    Hello, I have question about Redirect function. Why Golf use 301 not 302 by default. Because I think redirect with 302 use more than 301. So Is default value should be 302?.

    And another problem with 301 is browser will cache the redirection even if you disabled the redirection from the server level. ref: http://stackoverflow.com/questions/1393280/http-redirect-301-permanent-vs-302-temporary

    Thanks for created Golf, I just question and suggestion. Sorry for my bad english.

  • Update tag version

    Update tag version

    Hello I'm use gopkg to download the dependency by using go get gopkg.in/dinever/golf.v0.

    It download the v0.2 not a master branch. and it not provide some function in docs. Like Context.SetHeder(), Contextext.sendStatus(), app.Use(), that master branch have.

    Thank you.

  • Add JSONIndent method

    Add JSONIndent method

    I've been (slowly) working on https://github.com/dinever/dingo/issues/6, and noticed that the output of ctx.JSON wasn't very human-readable, since it just uses json.MarshalIndent. I really like the way GitHub has a sort of self-documenting API, and has easy-to-read JSON output, since it is formatted nicely. This PR adds support for the json.MarshalIndent method inside ctx, so that users can choose how to format their JSON output.

  • Getting more done in GitHub with ZenHub

    Getting more done in GitHub with ZenHub

    Hola! @guoziyan has created a ZenHub account for the dinever organization. ZenHub is the leading team collaboration and project management solution built for GitHub.


    How do I use ZenHub?

    To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.

    What can ZenHub do?

    ZenHub adds a series of enhancements directly inside the GitHub UI:

    • Real-time, customizable task boards for GitHub issues;
    • Burndown charts, estimates, and velocity tracking based on GitHub Milestones;
    • Personal to-do lists and task prioritization;
    • “+1” button for GitHub issues and comments;
    • Drag-and-drop file sharing;
    • Time-saving shortcuts like a quick repo switcher.

    Add ZenHub to GitHub

    Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @guoziyan.

    ZenHub Board

  • Print out stack trace with when error occurs

    Print out stack trace with when error occurs

    It would be great if someone could add some code here to enable stack trace logging for debugging.

    And it would be great if stack trace can be printed on the error page, like this:

    golang_trace-1024x431

  • add TLS support

    add TLS support

    add TLS support // Run the Golf Application.

    func (app *Application) RunTLS(addr, certFile, keyFile) {
        err := http.ListenAndServeTLS(addr, certFile, keyFile, app)
        if err != nil {
            panic(err)
        }
    }
    
  • Fixes default HTTP redirection

    Fixes default HTTP redirection

    Changes:

    • Changed default HTTP redirection status to 302, fixes #26
    • Added Context.Redirect301 for 301 redirection
    • Fixed several golint warnings
    • Added Go 1.7 and 1.8 to .travis.yml
  • Improved MemorySession

    Improved MemorySession

    1. Moved Session into a middleware.
    2. Add mutex in MemorySessionManager to avoid the race condition. Fixes #14
    3. Disable session by default
    4. Add method Count to SessionManager interface
    5. Improved test cases for sessions and XSRF protection
  • Adding mutex in MemorySessionManager.NewSession

    Adding mutex in MemorySessionManager.NewSession

    When performing stress testing, I found that concurrent session writes raised an error:

    fatal error: concurrent map writes
    
    goroutine 103 [running]:
    runtime.throw(0x8bfbf0, 0x15)
        /usr/lib/go/src/runtime/panic.go:530 +0x90 fp=0xc8201735a8 sp=0xc820173590
    runtime.mapassign1(0x742fc0, 0xc820011590, 0xc8201736b0, 0xc820173680)
        /usr/lib/go/src/runtime/hashmap.go:445 +0xb1 fp=0xc820173650 sp=0xc8201735a8
    github.com/dinever/golf.(*MemorySessionManager).NewSession(0xc820026058, 0x0, 0x0, 0x0, 0x0)
        /home/ubuntu/go/src/github.com/dinever/golf/session.go:54 +0x19c fp=0xc8201736e0 sp=0xc820173650
    github.com/dinever/golf.(*Context).generateSession(0xc8206d2200, 0x0, 0x0)
        /home/ubuntu/go/src/github.com/dinever/golf/context.go:63 +0x58 fp=0xc820173758 sp=0xc8201736e0
    github.com/dinever/golf.(*Context).retrieveSession(0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/context.go:76 +0x88 fp=0xc8201737d8 sp=0xc820173758
    github.com/dinever/golf.(*Application).handler(0xc820070550, 0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/app.go:75 +0x489 fp=0xc820173990 sp=0xc8201737d8
    github.com/dinever/golf.(*Application).(github.com/dinever/golf.handler)-fm(0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/app.go:91 +0x2a fp=0xc8201739a8 sp=0xc820173990
    github.com/dinever/golf.XSRFProtectionMiddleware.func1(0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/middleware.go:61 +0x150 fp=0xc820173a10 sp=0xc8201739a8
    github.com/dinever/golf.RecoverMiddleware.func1(0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/middleware.go:84 +0x56 fp=0xc820173a38 sp=0xc820173a10
    github.com/dinever/golf.LoggingMiddleware.func1(0xc8206d2200)
        /home/ubuntu/go/src/github.com/dinever/golf/middleware.go:44 +0x67 fp=0xc820173b30 sp=0xc820173a38
    github.com/dinever/golf.(*Application).ServeHTTP(0xc820070550, 0x7f5cff26c890, 0xc820057110, 0xc82070e7e0)
        /home/ubuntu/go/src/github.com/dinever/golf/app.go:91 +0xc2 fp=0xc820173b70 sp=0xc820173b30
    net/http.serverHandler.ServeHTTP(0xc820054500, 0x7f5cff26c890, 0xc820057110, 0xc82070e7e0)
        /usr/lib/go/src/net/http/server.go:2081 +0x19e fp=0xc820173bd0 sp=0xc820173b70
    net/http.(*conn).serve(0xc8204cce00)
        /usr/lib/go/src/net/http/server.go:1472 +0xf2e fp=0xc820173f98 sp=0xc820173bd0
    runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc820173fa0 sp=0xc820173f98
    created by net/http.(*Server).Serve
        /usr/lib/go/src/net/http/server.go:2137 +0x44e
    

    I think we need to add something like a mutex on the in MemorySessionManager.NewSession to fix this.

  • : runtime error: invalid memory address or nil pointer dereference

    : runtime error: invalid memory address or nil pointer dereference

    package main
    
    import (
    "github.com/dinever/golf"
     
    )
    
     
    
    func pageHandler(ctx *golf.Context) {
    	ctx.Send("Page: " + ctx.Param("page"))
    }
    func main() {
    	app := golf.New()
    
    	 
    	app.Get("/p/:page/", pageHandler)
    	app.Run(":9000")
    }
    

    visit http://localhost:9000/p/

  • ctx.Write undefined (type *golf.Context has no field or method Write)

    ctx.Write undefined (type *golf.Context has no field or method Write)

    package main
    
    import "github.com/dinever/golf"
    
    func pageHandler(ctx *golf.Context) {
      ctx.Write("Page: " + ctx.Param("page"))
    }
    
    func main() {
      app := golf.New()
      app.Get("/p/:page/", pageHandler)
      app.Run(":9000")
    }
    
    
    
  • WebSockets & File Upload

    WebSockets & File Upload

    Both appears to not be possible - FormValue does not contain any data, if it is a file. For WebSockets, it would require to expose net/http handlers, which doesn't appear to be possible.

    Is there any way to make either of those work inside Golf?

  • Use a pool for MemorySession creating

    Use a pool for MemorySession creating

    Would like to see a MemorySession pool in the MemorySessionManager.

    We can use the pool for new MemorySession creation to avoid frequent memory allocation.

  • Secure cookies

    Secure cookies

    Currently Golf stores cookies explicitly. Let's create a secure cookie method Context.SecureCookie & Context.SetSecureCookie to allow encrypting the cookies using a symmetric key.

    Before using the secure cookie, the user should set a secret_token, which will be used as the symmetric encryption key in the app configuration.

  • Route path to another app.

    Route path to another app.

    Router should have the ability to route a path to another app, so that there can be several apps in a single project.

    Like this:

    app = NewApp()
    anotherApp = NewApp()
    app.Route("/admin", anotherApp)
    
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Jan 5, 2023
Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

Nov 14, 2022
The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

Jul 14, 2022
⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Dec 8, 2022
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch

It is still under development, so please do not use it. We plan to release v.1.0.0 in the summer. roche is a web framework optimized for microservice

Sep 19, 2022
A powerful go web framework for highly scalable and resource efficient web application

webfr A powerful go web framework for highly scalable and resource efficient web application Installation: go get -u github.com/krishpranav/webfr Exa

Nov 28, 2021
A powerful go web framework for highly scalable and resource efficient web application

A powerful go web framework for highly scalable and resource efficient web application

Oct 3, 2022
A web app built using Go Buffalo web framework

Welcome to Buffalo Thank you for choosing Buffalo for your web development needs. Database Setup It looks like you chose to set up your application us

Feb 7, 2022
re:Web enables classic web applications to run on AWS Lambda.
re:Web enables classic web applications to run on AWS Lambda.

re:Web re:Web enables classic web applications to run on AWS Lambda. re:Web interfaces with the Lambda Runtime API. It translates API Gateway requests

Jan 1, 2023
Chainrand contract + web frontend + web backend

Chainrand-web This repo contains the implementation of Chainrand. https://chainrand.io Smart Contract Contains functionality to tie a Chainlink VRF to

Dec 8, 2021
Gin is a HTTP web framework written in Go (Golang).
Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Jan 3, 2023
An ideally refined web framework for Go.

Air An ideally refined web framework for Go. High-performance? Fastest? Almost all web frameworks are using these words to tell people that they are t

Dec 15, 2022
An opinionated productive web framework that helps scaling business easier.
An opinionated productive web framework that helps scaling business easier.

appy An opinionated productive web framework that helps scaling business easier, i.e. focus on monolith first, only move to microservices with GRPC la

Nov 4, 2022
BANjO is a simple web framework written in Go (golang)

BANjO banjo it's a simple web framework for building simple web applications Install $ go get github.com/nsheremet/banjo Example Usage Simple Web App

Sep 27, 2022
beego is an open-source, high-performance web framework for the Go programming language.
beego is an open-source, high-performance web framework for the Go programming language.

Beego Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services. It is inspired by To

Jan 1, 2023
High performance, minimalist Go web framework
High performance, minimalist Go web framework

Supported Go versions As of version 4.0.0, Echo is available as a Go module. Therefore a Go version capable of understanding /vN suffixed imports is r

Jan 2, 2023
⚡️ Express inspired web framework written in Go
⚡️ Express inspired web framework written in Go

Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development w

Jan 2, 2023
Go web framework with a natural feel

Fireball Overview Fireball is a package for Go web applications. The primary goal of this package is to make routing, response writing, and error hand

Nov 9, 2022