A lightweight RESTful web framework for Go

Goweb

A lightweight RESTful web framework for Go.

Goweb A lightweight RESTful web framework for Go.

wercker status

Who uses Goweb?

  • "Using Goweb has greatly simplified the creation, maintenance, and consistency of several of our internal services, allowing us to focus our effort on the underlying behavior of the services themselves." Derek Buitenhuis, Vimeo
  • "We are actively developing with Goweb to implement the REST api in-front of a neural network application" Jon McMillan, MCN Healthcare
  • "We are developing an API on top of Goweb that will power our platform as well as allow customers to access our data via a REST API." Robert Mulley, CB Insights

Are you using Goweb?

We are looking to put together a list of companies / people that are using Goweb. If you would like to help promote Goweb, and be included in the list, please comment on our issue and we'll get it going. Thanks.

Get started

  • To install, run go get github.com/stretchr/goweb
  • Import the package as usual with import "github.com/stretchr/goweb" in your code.
  • Look at the example_webapp project for some ideas of how to get going
  • Read the Goweb API Documentation
  • To update to the latest version of goweb, just run go get -u github.com/stretchr/goweb

Features

  • Drastically improved path matching
  • Cleaner interface for responding (e.g. goweb.API.RespondWithData, and goweb.Respond.WithRedirect)
  • More control over standard response object for API responses
  • Cleaner RESTful interface design
    • Default OPTIONS implementation that informs clients what methods the controller exposes
  • Easily publish static files as well as code driven output
  • Much easier to write testable code
  • Better package structure
  • Modular design, making adding new stuff easy
  • Handler mechanism to easily add pre and post handlers to certain requests
  • Uses stretchr/codecs package allowing better support for multiple formats
  • Easily match paths using Regex instead
  • Better error management
  • Performance improvements from Goweb 1

Interesting articles

People who use Goweb also use

  • Gomniauth - Authentication package (OAuth2 etc.)

Requirements

  • Goweb runs on Go 1.1

Contributing

Please feel free to submit issues, fork the repository and send pull requests. Be sure to check out our development practices before you get going.

When submitting an issue, we ask that you please include steps to reproduce the issue so we can see it on our end also!

Licence

Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell

Please consider promoting this project if you find it useful.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Owner
Stretchr, Inc.
Tame your unstructured data - We <3 open-source.
Stretchr, Inc.
Comments
  • Collect a list of people using Goweb

    Collect a list of people using Goweb

    We are looking to put together a list of companies / people that are using Goweb. If you would like to help promote Goweb, and be included in the list, please comment on this issue and we'll get it going.

    Thanks, Goweb team

  • Why not use Goweb?

    Why not use Goweb?

    Please leave a comment and tell us:

    • Why you chose not to use Goweb
    • Did it lack something you needed?
    • Do you think the project would benefit from an additional capability?
  • Proposed change to HTTP Methods

    Proposed change to HTTP Methods

    Since POST should create resources, I propose we change the way Goweb maps the RESTful interfaces in the following way.

    These will stay the same:

    RestfulReader Read = GET /path/{id}
    RestfulManyReader ReadMany = GET /path
    RestfulCreator Create = POST /path
    RestfulDeletor Delete = DELETE /path/{id}
    RestfulManyDeleter DeleteMany = DELETE /path
    (OPTIONS and HEAD will remain the same)    
    

    These will change from:

    RestfulUpdater Update = PUT /path/{id}
    RestfulReplacer Replace = POST /path/{id}
    RestfulManyUpdater UpdateMany = PUT /path
    

    to

    RestfulUpdater Update = PATCH /path/{id}
    RestfulReplacer Replace = PUT /path/{id}
    RestfulManyUpdater UpdateMany = PATCH /path
    
    • Since this will break existing interfaces, it's an important thing to carefully consider the consequences.
  • Don't envelop data in responses by default

    Don't envelop data in responses by default

    HI,

    maybe I'm missing something but I can't find any obvious way to turn off enveloping of data in responses (http://godoc.org/github.com/stretchr/goweb/responders#pkg-constants)

    Data enveloping should not be default (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#envelope) but rather let the API creator decide whether to support it or not.

  • MapController, MapStaticFile, MapStatic don't accept MatcherFuncs

    MapController, MapStaticFile, MapStatic don't accept MatcherFuncs

    It seems slightly odd that Map, MapBefore, and MapAfter all accept MatcherFuncs as additional parameters, while MapController, MapStaticFile, and MapStatic don't.

    Use Case:

    I am writing a RESTful API. I want a different controller to be called for different types of Accept headers. When the Accept header includes 'text/html', I want to display my generated godoc documentation (using MapStatic or MapStaticFile). When the Accept header includes 'application/-+', I want to run the an API controller that runs the correct version.

    I want to do this by essentially passing a MatcherFunc to the MapController, MapStatic, etc methods which checks the Accept header against a list of acceptable values. But currently, they cannot accept MatcherFuncs.

    I'm forking the repo and tossing that in myself (because it's easy), and ... will probably make a pull request after I get it working, because ... that's the right thing to do? I think? Goodness, I'm too used to bugzilla and attaching patches. I feel old.

    [edit] If there's a better way to do this, please let me know. I haven't been doing this very long, but from what I've seen, that seems to be the best route. [/edit]

  • security bug: static file serving arbitrary file/source

    security bug: static file serving arbitrary file/source

    Hi, when a server comes up with a static serving directory. from client side it is able to access arbitrary file using relative path.

    for example: my server is serving /static for static files, i can get /etc/passwd by requesting /static/../../../../../../etc/passwd

    $ telnet localhost 9123
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /static/../../../../../../etc/passwd HTTP/1.0
    
    HTTP/1.0 200 OK
    Accept-Ranges: bytes
    Content-Length: 1234
    Content-Type: text/plain; charset=utf-8
    Last-Modified: Sat, 01 Aug 2012 05:13:28 GMT
    X-Custom-Header: Goweb
    Connection: close
    Date: Wed, 05 Jun 2013 04:30:46 GMT
    
    root:x:0:0:root:/root:/bin/bash
    ........
    
  • codecs: Cannot call PublicData(map[string]int) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object.

    codecs: Cannot call PublicData(map[string]int) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object.

    A simple REST controller with a method:

    func (ctrl _MyController) ReadMany(ctx context.Context) error { var Things []_Thing thing := new(Thing) thing.Id = "A" thing.Text = "A Thing!" Things = append(Things, thing) return goweb.API.RespondWithData(ctx, Things) }

    Request: GET /api/my

    Leads to the following in the console:

    2013/06/12 10:53:32 http: panic serving 127.0.0.1:49779: codecs: Cannot call PublicData([]_controllers.Thing) because it does not implement codecs.Facade (i.e. needs PublicData method) and is not a Data object. goroutine 11 [running]: net/http.func·007() /usr/local/go/src/pkg/net/http/server.go:1022 +0xac github.com/stretchrcom/codecs.publicData(0x274fe0, 0xc200151c60, 0x0, 0x0, 0x6e7a30, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/codecs/facade.go:106 +0x2fe github.com/stretchrcom/codecs.PublicData(0x274fe0, 0xc200151c60, 0x0, 0x1, 0x2842a0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/codecs/facade.go:63 +0x42 github.com/stretchrcom/goweb/responders.(_GowebAPIResponder).Respond(0xc2000eb7e0, 0xc2000dc7e0, 0xc200157c40, 0xc8, 0x274fe0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/responders/goweb_api_responder.go:130 +0xa8 github.com/stretchrcom/goweb/responders.(_GowebAPIResponder).RespondWithData(0xc2000eb7e0, 0xc2000dc7e0, 0xc200157c40, 0x274fe0, 0xc200151c60, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/responders/goweb_api_responder.go:155 +0x6c project/api/controllers.(_MyController).ReadMany(0xc2000008a8, 0xc2000dc7e0, 0xc200157c40, 0x1, 0x1, ...) /Users/alex/Documents/Work/sources/backend/src/project/api/controllers/poi.go:37 +0x171 github.com/stretchrcom/goweb/controllers.RestfulManyReader.ReadMany·fm(0xc2000dc7e0, 0xc200157c40, 0x0, 0x0) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/mapping.go:234 +0x52 github.com/stretchrcom/goweb/handlers.(_PathMatchHandler).Handle(0xc2000ebf00, 0xc2000dc7e0, 0xc200157c40, 0x1, 0x0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/path_match_handler.go:137 +0x38 github.com/stretchrcom/goweb/handlers.Pipe.Handle(0xc200100600, 0x17, 0x20, 0xc2000dc7e0, 0xc200157c40, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/pipe.go:61 +0x121 github.com/stretchrcom/goweb/handlers.(_Pipe).Handle(0xc200151800, 0xc2000dc7e0, 0xc200157c40, 0xdd301, 0x0, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/default_error_handler.go:0 +0x9a github.com/stretchrcom/goweb/handlers.Pipe.Handle(0xc20014d690, 0x3, 0x3, 0xc2000dc7e0, 0xc200157c40, ...) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/pipe.go:61 +0x121 github.com/stretchrcom/goweb/handlers.(_HttpHandler).ServeHTTP(0xc2001468c0, 0xc2001544c0, 0xc200157bd0, 0xc20014b680) /Users/alex/Documents/Work/sources/backend/src/github.com/stretchrcom/goweb/handlers/http_handler.go:67 +0xac net/http.serverHandler.ServeHTTP(0xc200147820, 0xc2001544c0, 0xc200157bd0, 0xc20014b680) /usr/local/go/src/pkg/net/http/server.go:1517 +0x16c net/http.(_conn).serve(0xc2000e26c0) /usr/local/go/src/pkg/net/http/server.go:1096 +0x765 created by net/http.(*Server).Serve /usr/local/go/src/pkg/net/http/server.go:1564 +0x266

  • Design views in Goweb

    Design views in Goweb

    Views are a key part of web development, and if you're not building a data API you will likely be managing views in some way within Goweb.

    We would like to implement a solution for new projects that will make managing views as easy as it is in Ruby on Rails.

    Initial thinking:

    • Must be easy to render a view
    • View rendering service must be interchangeable; if people want to use another templating framework, they should easily be able to
    • Helpers for common stuff (like building URLs etc.)
    • Can a controller automatically be mapped using reflection? So /controller/action would map to the action method on the controller class. E.g. /people/new would map to PeopleController and call method New.
  • Should the goweb `import` path include v2?

    Should the goweb `import` path include v2?

    Should the Goweb import path include the version number?

    i.e.

    import (
      "github.com/stretchrcom/goweb/v2"
    )
    

    The namespace would still be goweb allowing clean code.

  • Example for injecting database into context

    Example for injecting database into context

    Is there a way to maintain a database connection (using https://github.com/vmihailenco/redis/tree/master/v2 for example) and then inject access to it into the context so that each request can use the connection (thread-safely) without having to reconnect?

    If you have an example of the correct way of doing this, it'd be greatly appreciated.

  • RestfulManyUpdater has wrong mapping

    RestfulManyUpdater has wrong mapping

    In the docs (http://godoc.org/github.com/stretchr/goweb/controllers#RestfulManyUpdater), the RestfulManyUpdater has this mapping:

    GET /resources/{id}

    Which is not correct and should instead be:

    PUT /resources

    I haven't check if it is only an error in documentation or if the implementation is incorrect also

  • Why aren't dotted values allowed for resource ids?

    Why aren't dotted values allowed for resource ids?

    goweb seems to always assume that a . means a file extension - but when using a controller this doesn't really make sense.

    e.g. DELETE /something/10.0.0.1 would call somethingController.Delete("10", ctx) - which seems really very wrong ...

  • Testing Controllers?

    Testing Controllers?

    I was looking at webcontext_test and it more or less works for me, but I noticed the note that testify/http/TestResponseWriter is deprecated. Is there a new approach that uses ResponseRecorder? I tried whipping up my own TestContext using ResponseRecorder but I didn't have much luck getting it going.

  • Figure out real status with always200

    Figure out real status with always200

    Here's a situation we've faced. We store some media objects (AWS S3 backend) and the API returns temporary redirects with timestamped signature in the URL. The resource requires our custom token-based authentication (Authorization header in request). The client-side (JS app) uses direct URLs to resources in tags like but it fails because of authentication. When using a XHR to perform authorised request the XHR follows redirect automatically (no chance to switch it off) and this one is also not an option.

    The always200=true therefore is a good way to overcome this problem. But in this case the response from the server contain http status 200 and of course an empty body (originally we send a temporary redirect). Therefore it's nearly impossible to figure out what's happening on the server (without looking into the headers of course).

    The question is would it be an expected behaviour from goweb to force to include a body, where it was not specified in cases with awlays200 to contain at least { s:REAL_STATUS} ?

  • The server's binary gets all the test flags

    The server's binary gets all the test flags

    I've noticed weird flags appear when I print the -help of my binary:

    Usage of app/bin/server: -conf="etc/config.yml": Configuration file -ip="0.0.0.0": IP address to bind server to. Example: 127.0.0.1 -port=8080: Port number to bind server to. Example: 8080 -test.bench="": regular expression to select benchmarks to run -test.benchmem=false: print memory allocations for benchmarks -test.benchtime=1s: approximate run time for each benchmark -test.blockprofile="": write a goroutine blocking profile to the named file after execution -test.blockprofilerate=1: if >= 0, calls runtime.SetBlockProfileRate() -test.cpu="": comma-separated list of number of CPUs to use for each test -test.cpuprofile="": write a cpu profile to the named file during execution -test.memprofile="": write a memory profile to the named file after execution -test.memprofilerate=0: if >=0, sets runtime.MemProfileRate -test.parallel=1: maximum test parallelism -test.run="": regular expression to select tests and examples to run -test.short=false: run smaller test suite to save time -test.timeout=0: if positive, sets an aggregate time limit for all tests -test.v=false: verbose: print additional output

    As far as I can see from:

    $ go list -f '{{join .Deps "\n"}}' github.com/stretchr/goweb | grep testing testing

    Goweb can be the reason... Any ideas how to get rid of these flags?

  • Simplified API in the future? Goweb use too many []interface{} for args

    Simplified API in the future? Goweb use too many []interface{} for args

    I'm going to use Goweb for the next project, after reading the API document I feel Goweb use too many ...interface{} for the function agrs. I give some flexible but sometime give some confusions. Why don't we just provide the most general API for the function? For example, goweb.Map should be:

    func Map(fn func(c context.Context) error, path string, methods []string, matchers []handlers.MatcherFunc) (handlers.Handler, error)
    

    or goweb.MapController should be just:

    func MapController(controller interface{}, path string) error
    

    I know this is not that importan and hard to change because you will break your old code but it still worth something! I bet that many of us love Go because the simplicity and clarity (by the lack of function overloading and something else)

    Thanks for the team for your great package!

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
Eudore is the core of a golang lightweight web framework.

Eudore eudore是一个golang轻量级web框架核心,可以轻松扩展成一个技术栈专用框架,具有完整框架设计体系。 反馈和交流请加群组:QQ群373278915。 Features 易扩展:主要设计目标、核心全部解耦,接口即为逻辑。 简单:对象语义明确,框架代码量少复杂度低,无依赖库。 易用

Nov 7, 2022
A lightweight MVC framework for Go(Golang)

utron utron is a lightweight MVC framework in Go (Golang) for building fast, scalable and robust database-driven web applications. Features Postgres,

Dec 31, 2022
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
Web framework for creating apps using Go in Google AppEngine

Welcome to app.go v3.0 app.go is a simple web framework for use in Google AppEngine. Just copy the app folder to your working folder and import it fro

Mar 21, 2021
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.
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.

Gin Web Framework Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks

Jan 2, 2023
Goal is a toolkit for high productivity web development in Go language in the spirit of Revel Framework that is built around the concept of code generation.

Goal Goal is a set of tools for high productivity web development in Go language. Goal, being mostly inspired by Revel Framework and its discussions,

Sep 27, 2021
a golang web mvc framework, like asp.net mvc.

goku goku is a Web Mvc Framework for golang, mostly like ASP.NET MVC. doc & api Installation To install goku, simply run go get github.com/QLeelulu/go

Dec 7, 2022
A high level web-framework for Go

go-start is a high level web-framework for Go, like Django for Python or Rails for Ruby. Installation: go get github.com/ungerik/go-start Documentatio

Dec 24, 2022
Fast and Reliable Golang Web Framework
Fast and Reliable Golang Web Framework

Gramework The Good Framework Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware What is i

Dec 18, 2022
Mango is a modular web-application framework for Go, inspired by Rack, and PEP333.

Mango Mango is a modular web-application framework for Go, inspired by Rack and PEP333. Note: Not actively maintained. Overview Mango is most of all a

Nov 17, 2022
Classy web framework for Go

Martini NOTE: The martini framework is no longer maintained. Martini is a powerful package for quickly writing modular web applications/services in Go

Dec 29, 2022
A Go framework for building JSON web services inspired by Dropwizard

Tiger Tonic A Go framework for building JSON web services inspired by Dropwizard. If HTML is your game, this will hurt a little. Like the Go language

Dec 9, 2022
The web framework for Golang
The web framework for Golang

uAdmin the Golang Web Framework Easy to use, blazing fast and secure. Originally open source by IntegrityNet Solutions and Services For Documentation:

Dec 24, 2022
Simple web framework for go, still quite beta at this point

WFDR Framework - Beta Release New 18/Feb/2012: Updated for go 1.0, new directory layout to take advantage of the go build tool. Background There's a m

Feb 11, 2021
A lightweight and fast http router from outer space

Alien Alien is a lightweight http router( multiplexer) for Go( Golang ), made for humans who don't like magic. Documentation docs Features fast ( see

Nov 13, 2022
:bullettrain_side: High-performance web server for Go.
:bullettrain_side: High-performance web server for Go.

Aero is a high-performance web server with a clean API. Installation go get -u github.com/aerogo/aero/... Usage Run this in an empty directory: aero -

Dec 8, 2022
package for building REST-style Web Services using Go

go-restful package for building REST-style Web Services using Google Go Code examples using v3 REST asks developers to use HTTP methods explicitly and

Jan 1, 2023
The easiest way to create web applications with Go

web.go web.go is the simplest way to write web applications in the Go programming language. It's ideal for writing simple, performant backend web serv

Dec 24, 2022