A fantastic modular Go web framework boiled with black magic.

Overview

Flamego

GitHub Workflow Status Codecov GoDoc Sourcegraph

A fantastic modular Go web framework boiled with black magic.

Getting started

The minimum requirement of Go is 1.16.

To install Flamego:

go get github.com/flamego/flamego

To begin with:

package main

import "github.com/flamego/flamego"

func main() {
	f := flamego.Classic()
	f.Get("/", func() string {
		return "Hello, Flamego!"
	})
	f.Run()
}

License

This project is under the MIT License. See the LICENSE file for the full license text.

Comments
  • Returning a byte slice with an error outputs an empty HTTP body

    Returning a byte slice with an error outputs an empty HTTP body

    Component

    Core framework

    Middleware

    n/a

    Version

    v1.1.0

    Describe the bug

    I'm not sure if this is supported but when I'm using a handler that returns ([]byte, error), the response is empty. It works when I only return []byte though.

    To reproduce

    package main
    
    import (
    	"github.com/flamego/flamego"
    )
    
    func main() {
    	f := flamego.Classic()
    
    	f.Get("/", func() ([]byte, error) {
    		return []byte(`{"hello": "world"}`), nil
    	})
    
    	f.Run()
    }
    

    Expected behavior

    See the output in the browser

    Additional context

    Here are the relevant logs, we can see that the handler actually returns 0 bytes.

    [Flamego] 2022-04-08 15:23:03: Started GET / for 100.100.100.100
    [Flamego] 2022-04-08 15:23:03: Completed GET / 0  in 100.3µs
    

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature 
    opened by asdine 4
  • Encountered a GOB error when using Session and CSRF at the same time

    Encountered a GOB error when using Session and CSRF at the same time

    Component

    Middleware

    Middleware

    https://github.com/flamego/session

    Version

    1.2.1

    Describe the bug

    在使用redis存储session时遇到问题 gob: type not registered for interface: time.Time

    To reproduce

    配置 session 使用 Redis 作为存储。 然后后部加上csrf。 可在flamego/session/redis/redis.go:68 下断点复现。 image

    Expected behavior

    正常应该无报错

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    💊 bug 
    opened by asjdf 3
  • static: support setting

    static: support setting "Cache-Control"

    Describe the pull request

    This PR adds a Cache-Control option for static files that works in the same fashion as the existing Expires option.

    Link to the issue: n/a

    Checklist

    • [x] I agree to follow the Code of Conduct by submitting this pull request.
    • [x] I have read and acknowledge the Contributing guide.
    • [x] I have added test cases to cover the new code.
    opened by pharrisee 3
  • router: support using `http.MethodGet`, `http.MethodPost` to replace

    router: support using `http.MethodGet`, `http.MethodPost` to replace "GET,POST" in `f.Routes`

    Component

    Core framework

    Middleware

    n/a

    Is your feature request related to a problem? Please describe

    To register a route for multiple HTTP methods, one would use follows:

    f.Routes("/", "GET,POST", ...)
    

    However, the use of "GET,POST" looks very non-elegant, and one always needs to type in full characters without editor's auto-completion (because this is literal string).

    Describe the solution you'd like

    The net/http package provides constants for each HTTP method, e.g. http.MethodGet, we should be able to do things more elegant like:

    f.Routes("/", http.MethodGet, http.MethodPost, <my handlers>)
    

    Because these constants are strings after all, the router should be able to distinguished them from handlers, and magically do the trick for users.

    Describe alternatives you've considered

    n/a

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature ðŸ”† roadmap 
    opened by unknwon 3
  • session: support auto-create table for PostgreSQL and MySQL

    session: support auto-create table for PostgreSQL and MySQL

    Component

    Middleware

    Middleware

    https://github.com/flamego/session

    Is your feature request related to a problem? Please describe

    The session middleware require manual creation of the table for PostgreSQL and MySQL backend.

    Describe the solution you'd like

    Add an option to the postgres.Config and mysql.Config like the following (field name need to be discussed):

    type Config struct{
    	// ...
    	InitTable bool
    }
    

    Which automatically creates the table when not exists.

    The SQL to create the table can be derived from the tests.

    Describe alternatives you've considered

    Live with it.

    Additional context

    Feel free to ask more details or clarifying questions!

    If you would like to contribute on the implementation, please:

    1. Comment on the issue for taking the responsibility so everyone knows.
    2. Acknowledge that the expected timeline is one week.

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    👋 good first issue ðŸ”¨ enhancement 
    opened by unknwon 3
  • mod: bump github.com/alecthomas/participle/v2 from 2.0.0-alpha10 to 2.0.0-beta.1

    mod: bump github.com/alecthomas/participle/v2 from 2.0.0-alpha10 to 2.0.0-beta.1

    Bumps github.com/alecthomas/participle/v2 from 2.0.0-alpha10 to 2.0.0-beta.1.

    Commits
    • 71ce420 document parameter "filename" for the Parser methods
    • 9bf3906 Make ParseError public
    • dcb4a85 Make Trace a ParseOption (#238)
    • cac0186 fix documentation typos
    • f8162a8 Document Union in README.
    • 583c334 Allow custom & union productions (#233)
    • fcdcf73 tutorial: make it work with the default lexer (parse integers)
    • 2246ffc handle error from root Parseable
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    🤖 dependencies 
    opened by dependabot[bot] 2
  • route: add `Headers` method for matching request headers

    route: add `Headers` method for matching request headers

    Describe the pull request

    Use regex to match headers!

    Link to the issue: fixes https://github.com/flamego/flamego/issues/132

    Checklist

    • [x] I agree to follow the Code of Conduct by submitting this pull request.
    • [x] I have read and acknowledge the Contributing guide.
    • [x] I have added test cases to cover the new code.

    Followup

    • [x] Update docs on flamego.dev
    • [x] Update docs on flamego.cn
    opened by unknwon 2
  • router: add support for `HeadersRegexp`

    router: add support for `HeadersRegexp`

    Component

    Core framework

    Middleware

    n/a

    Is your feature request related to a problem? Please describe

    hi, it that any plan to support router with HeadersRegexp? i want to write S3 web service (looks like minio) with flamego ,but it miss HeadersRegexp func to filter request with header.

    https://github.com/minio/minio/blob/master/cmd/api-router.go#L242

    // HeadersRegexp accepts a sequence of key/value pairs, where the value has regex
    // support. For example:
    //
    //     r := mux.NewRouter()
    //     r.HeadersRegexp("Content-Type", "application/(text|json)",
    //               "X-Requested-With", "XMLHttpRequest")
    //
    // The above route will only match if both the request header matches both regular expressions.
    // If the value is an empty string, it will match any value if the key is set.
    // Use the start and end of string anchors (^ and $) to match an exact value.
    

    Describe the solution you'd like

    https://github.com/gorilla/mux/blob/d07530f46e1eec4e40346e24af34dcc6750ad39f/route.go#L255

    Describe alternatives you've considered

    https://github.com/minio/minio/blob/master/cmd/api-router.go#L242

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature ðŸ”† roadmap 
    opened by diluga 2
  • router: support `Routes` accepting multiple strings as method

    router: support `Routes` accepting multiple strings as method

    Describe the pull request

    Link to the issue: https://github.com/flamego/flamego/issues/113

    Checklist

    • [x] I agree to follow the Code of Conduct by submitting this pull request.
    • [x] I have read and acknowledge the Contributing guide.
    • [x] I have added test cases to cover the new code.

    Followup

    • [x] Update docs on flamego.dev
    • [x] Update docs on flamego.cn
    opened by unknwon 2
  • validator: make examples to work with i18n

    validator: make examples to work with i18n

    Component

    Middleware

    Middleware

    https://github.com/flamego/validator

    Is your feature request related to a problem? Please describe

    The validator module should be able to work with github.com/go-i18n/i18n and github.com/flamego/i18n, we need to make some example or make code changes to make that happen.

    Describe the solution you'd like

    n/a

    Describe alternatives you've considered

    n/a

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature ðŸ›°ï¸ middleware ðŸ”† roadmap 
    opened by unknwon 2
  • context: support default values for `Query` methods

    context: support default values for `Query` methods

    Describe the pull request

    Allow passing an optional second argument for Query methods as the default value. Also start using go-mockgen to generate mocks for interface.

    Link to the issue: fixes #125, fixes #77

    Checklist

    • [x] I agree to follow the Code of Conduct by submitting this pull request.
    • [x] I have read and acknowledge the Contributing guide.
    • [x] I have added test cases to cover the new code.

    Followup

    • [x] Update docs on flamego.dev
    • [x] Update docs on flamego.cn
    opened by unknwon 2
  • README: unified middleware format

    README: unified middleware format

    Describe the pull request

    unified middleware format

    Checklist

    • [x] I agree to follow the Code of Conduct by submitting this pull request.
    • [x] I have read and acknowledge the Contributing guide.
    • [ ] I have added test cases to cover the new code.
    opened by L2ncE 0
  • router: type-safe helpers for multiplex routes

    router: type-safe helpers for multiplex routes

    Component

    Core framework

    Middleware

    n/a

    Is your feature request related to a problem? Please describe

    Currently multiplex routes are supported via:

    f.Routes("/", http.MethodGet, http.MethodPost, <my handlers>)
    
    // or
    
    f.Routes("/", "GET,POST", ...)
    

    But neither of are both elegant and type-safe.

    Describe the solution you'd like

    Something like

    f.RoutePath("/").Methods(http.MethodGet, http.MethodPost).Handlers(...)
    

    Describe alternatives you've considered

    Live with it

    Additional context

    Derived from https://github.com/flamego/flamego/issues/113#issuecomment-1125895280

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature ðŸ”† roadmap 
    opened by unknwon 1
  • docs: add documentation for SSE middleware

    docs: add documentation for SSE middleware

    What needs to be improved? Please describe

    • [ ] Add both English and Chinese versions of SSE middleware.

    Update links to the docs on:

    • [ ] The "Middleware" section on the main repository's README
    • [ ] The "Getting help" section on each middleware repository's README
    • [ ] flamego.dev/middleware

    Why do you think it is important?

    This is a new middleware for Flamego.

    It was implemented in "dependency injection style" which is much different from the other Go web frameworks.

    So it's necessary for us to provide documentation for developers.

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    📖 documentation ðŸ›°ï¸ middleware ðŸ”† roadmap 
    opened by wuhan005 0
  • template: mysterious error

    template: mysterious error "failed to write out rendered HTML: short write"

    Component

    Middleware

    Middleware

    https://github.com/flamego/template

    Version

    1.0.0

    Describe the bug

    Occasionally seeing logs of "failed to write out rendered HTML: short write" printed to console.

    To reproduce

    Running https://github.com/asoul-sig/asouldocs for https://asouldocs.dev

    Expected behavior

    Not sure, is this a real error or should just be ignored? Maybe something wrong with the response body content length?

    Additional context

    Related: https://github.com/denoland/deno/issues/3478#issuecomment-564406922

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    💊 bug ðŸ›°ï¸ middleware 
    opened by unknwon 0
  • context: `RemoteAddr` is unsafe

    context: `RemoteAddr` is unsafe

    Component

    Core framework

    Middleware

    n/a

    Version

    1.1.0

    Describe the bug

    As the document mentioned, the RemoteAddr() method looks at the following things in the order to determine which one is more likely to contain the real client address.

    The X-Real-IP request header The X-Forwarded-For request header The http.Request.RemoteAddr field

    So the client's IP can be spoofed by setting the X-Real-IP or X-Forwarded-For header when the Flamego server is exposed directly to the internet.

    The Gin web framework has the same vulnerability before, check CVE-2020-28483 for details.

    I think we should create a new function called ClientIP() to get the client IP address from these headers. The RemoteAddr() can only get it from http.Request.RemoteAddr.

    Moreover, the Flame instance should allow the developers to set the trusted remote IP headers and the trusted proxies if they want to get the client IP from user-provided headers.

    To reproduce

    n/a

    Expected behavior

    n/a

    Additional context

    https://nvd.nist.gov/vuln/detail/CVE-2020-28483 https://github.com/gin-gonic/gin/issues/2473

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    📖 documentation 
    opened by wuhan005 3
  • middleware: add support for request rate limiting

    middleware: add support for request rate limiting

    Component

    Middleware

    Middleware

    https://github.com/zhqqqy/flamego-limit

    Is your feature request related to a problem? Please describe

    Web frameworks generally need the function of current limiting.

    Describe the solution you'd like

    I implemented a simple current limiting middleware based on the sliding window algorithm, which can be enabled in the specified router, and the current limiting key can be customized.

    Describe alternatives you've considered

    It may also be possible to implement current limiting algorithms such as token buckets based on this

    Additional context

    No response

    Code of Conduct

    • [X] I agree to follow this project's Code of Conduct
    🎯 feature ðŸ›°ï¸ middleware 
    opened by zhqqqy 0
Releases(v1.7.0)
  • v1.7.0(Oct 20, 2022)

    What's Changed

    • The minimum requirement of Go has been changed to 1.18 by @unknwon in https://github.com/flamego/flamego/pull/149

    Full Changelog: https://github.com/flamego/flamego/compare/v1.6.0...v1.7.0

    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Oct 19, 2022)

    What's Changed

    • static: support setting "Cache-Control" by @pharrisee in https://github.com/flamego/flamego/pull/143

    New Contributors

    • @pharrisee made their first contribution in https://github.com/flamego/flamego/pull/143

    Full Changelog: https://github.com/flamego/flamego/compare/v1.5.0...v1.6.0

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Jun 11, 2022)

    What's Changed

    • route: add Headers method for matching request headers by @unknwon in https://github.com/flamego/flamego/pull/133

    Full Changelog: https://github.com/flamego/flamego/compare/v1.4.0...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jun 1, 2022)

    What's Changed

    • router: support Routes accepting multiple strings as method by @unknwon in https://github.com/flamego/flamego/pull/129

    Full Changelog: https://github.com/flamego/flamego/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(May 30, 2022)

    What's Changed

    • context: support default values for Query methods by @unknwon in https://github.com/flamego/flamego/pull/127

    Full Changelog: https://github.com/flamego/flamego/compare/v1.2.1...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(May 13, 2022)

    What's Changed

    • response_writer: make read and write status code thread safe by @unknwon in https://github.com/flamego/flamego/pull/123

    Full Changelog: https://github.com/flamego/flamego/compare/v1.2.0...v1.2.1

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Apr 8, 2022)

    What's Changed

    • return_handler: support return values of ({string, []byte}, error) by @unknwon in https://github.com/flamego/flamego/pull/118

    Full Changelog: https://github.com/flamego/flamego/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Mar 4, 2022)

    What's Changed

    • router: support {**} as the shorthand for {**: **} by @unknwon in https://github.com/flamego/flamego/pull/93

    Full Changelog: https://github.com/flamego/flamego/compare/v1.0.1...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Dec 1, 2021)

    What's Changed

    • mod: bump github.com/fatih/color from 1.10.0 to 1.13.0 by @dependabot in https://github.com/flamego/flamego/pull/68
    • router: fix slash path trimming by @wuhan005 in https://github.com/flamego/flamego/pull/76

    Full Changelog: https://github.com/flamego/flamego/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Nov 28, 2021)

  • v1.0.0-rc.1(Nov 26, 2021)

Owner
Flamego
A fantastic modular Go web framework boiled with black magic.
Flamego
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

Paul Bellamy 371 Nov 17, 2022
GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

GoFrame English | 简体中文 GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang. If you're a

GoFrame 8.6k Nov 29, 2022
Modular C2 framework aiming to ease post exploitation for red teamers.

test.mp4 testvideo.mp4 Usage: Inside the command server you can reference beacons using either their list id or their unique id. For example if the ou

meet 170 Nov 9, 2022
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

Flamingo 327 Nov 13, 2022
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

golanger 298 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

null 8 Jul 14, 2022
Software modular synthesizer with Midi support

go-modular A software modular synthesizer with Midi support. !! Warning: High amplitude sounds can cause serious ear damage. Lower your headphone volu

AJ Zaffetti 15 Mar 31, 2022
Gookit 83 Oct 3, 2022
henrylee2cn 1.6k Nov 18, 2022
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

Riita 14 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

Krisna Pranav 13 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

null 22 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

Mike Okoth 0 Feb 7, 2022
laravel for golang,goal,fullstack framework,api framework

laravel for golang,goal,fullstack framework,api framework

桥边红药 17 Feb 24, 2022
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.

Gin-Gonic 64.6k Nov 23, 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

Aofei Sheng 419 Oct 31, 2022
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

appist 128 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

Nazarii Sheremet 20 Sep 27, 2022
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

astaxie 578 Nov 29, 2022