Giter Site home page Giter Site logo

andeya / faygo Goto Github PK

View Code? Open in Web Editor NEW
1.6K 104.0 259.0 50.47 MB

Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.

Home Page: https://github.com/henrylee2cn/faydoc

License: Apache License 2.0

Go 96.47% HTML 1.90% Smarty 1.32% JavaScript 0.25% CSS 0.06%
web-framework http2 golang server server-push parameter-binding auto-api-doc middleware httprouter shutdown-reboot-gracefully

faygo's Introduction

  • 😄 Stay hungry, Stay young
  • 🔭 Focus on:
    • Go
    • Rust
    • WebAssembly
    • Blockchain
    • Backend Architecture
    • Other technologies of interest

faygo's People

Contributors

andeya avatar bryant1410 avatar changyu72 avatar elithrar avatar forging2012 avatar k4s avatar leadrive avatar nickypeng avatar sunfmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faygo's Issues

如何自定义不存在的api

例如,当访问到不存在的api时,返回特定的json。net/http中只要HandlerFunc("/")同时另外HandlerFunc已存在的地址就行了。

nohup 运行时faygo日志进入了nohup.out

如题,在用nohup的方式运行faygo的时候,faygo日志写入了nohup.out
这显然不是我们期待的结果, 请问要怎么样保持faygo日志继续写入原来的文件里?
谢谢

Attribute Code Used from gorilla/securecookie

When fixing an issue, I came across code that is (in some parts) identical to code in the BSD licensed https://github.com/gorilla/securecookie codebase.

Specifically:

I'm not a stickler for licenses, and I don't know whether you are new to open-source (and thus OSS licensing!), but the concern here is that you are:

  • Copying upstream code in part, but not in whole, and thus introducing weaknesses in the process: #8
  • Isolating your users from any upstream fixes we make to securecookie
  • Already vendoring some code, but not all, which makes this appear intentional.

Can you please either:

  1. Import the securecookie library (vendored or otherwise) and, if necessary, wrap the functions for your own API?
    -or-
  2. Attribute the library correctly in all files where it is used as per https://github.com/gorilla/securecookie/blob/master/LICENSE

Thanks!

如何只给某些api使用filter

尝试使用

app := faygo.New("")
    app.
      Filter(xxx).
      Route("/api/x")
    app.
      Filter(yyy).
      Route("api/y")

发现xxx和yyy filter会都影响 api/x 和 api/y

运行报错

go版本 1.11,使用go mod做依赖管理。goland的go build运行出现以下报错。
../../pkg/mod/github.com/henrylee2cn/[email protected]/helper.go:59:9: undefined: ini.SyncINI

jwt中用到的Bearer,在某些ios会报错

在某些IOS上,前端访问faygo时,会报SyntaxError DOM Exception 12的错误。
原因是出在jwt中,token的设置带了一个空格。
可以参考
http://www.blogjava.net/laxxx/archive/2015/12/17/428705.html

问题的重现,可以在网上下载黑雷苹果模拟器,该模拟器带的Safira,刚好可以重现此问题。

我的解决办法是用/代替空格,或者二者都支持,当然需要修改下jwt.go的代码

func (mw *FaygoJWTMiddleware) jwtFromHeader(ctx *faygo.Context, key string) (string, error) {
	authHeader := ctx.HeaderParam(key)
	if authHeader == "" {
		return "", ErrEmptyAuthHeader
	}
	// faygo.Debug("jwtFromHeader:", authHeader)
	// ios某些版本,有空格的话,会报SyntaxError DOM Exception 12
	parts := strings.SplitN(authHeader, " ", 2)
	if len(parts) == 2 && parts[0] == mw.TokenHeadName {
		return parts[1], nil
	}
	parts = strings.SplitN(authHeader, "/", 2)
	if !(len(parts) == 2 && parts[0] == mw.TokenHeadName) {
		return "", ErrInvalidAuthHeader
	}

	return parts[1], nil
}

ctx.URL().Scheme is empty

ctx.URL() to JSON:

{
    "Scheme": "",
    "Opaque": "",
    "User": null,
    "Host": "",
    "Path": "/captcha",
    "RawPath": "",
    "ForceQuery": false,
    "RawQuery": "params=asdf",
    "Fragment": ""
}

Most of them are empty. How to get theirs value?

用了go mod去管理包,但是因为xorm的core已经变更为xorm.io,所以会报以下错误。

go: github.com/go-xorm/[email protected]: parsing go.mod: unexpected module path "xorm.io/core"

在go mod 中增加了这个的话,会报这个错误

replace github.com/go-xorm/core v0.6.3 => xorm.io/core v0.6.3

go: xorm.io/[email protected] used for two different module paths (github.com/go-xorm/core and xorm.io/core)

目前可以通过修改版本,但是又会引发另外一个错误

image

希望作者有空更新下ext里面的db插件

Fix grammar in github description

Your project description has some grammar errors, I would suggest the following instead:

Faygo is a fast and concise Go web framework that can be used to develop high-performance web apps (especially APIs) with less code. Just define a struct Handler, Faygo will automatically bind/verify the request parameters and generate the online API doc. https://github.com/henrylee2cn/faydoc

Also I do not quite understand what you mean by "especially API". Do you mean it is possible to easily create web services? Or do you mean your framework's API is good? You should clarify that or cut it from the description
Another point is that your description seems a bit long and detailed, maybe just remove everything starting at "Just define a struct Handler", things like these usually go in the README.

关于 config

大佬、我发现 faygo.New(appname) 只能通过ini配置

建议可以用代码setconfig吧

比如要读取环境变量的,ini没办法读取环境变量

url with trailing slash /index/100/ match route "/index/:id" return 301 not 404

package main

import (
	"github.com/henrylee2cn/faygo"
	"time"
)

type Index struct {
}

func (i *Index) Serve(ctx *faygo.Context) error {
	if ctx.CookieParam("faygoID") == "" {
		ctx.SetCookie("faygoID", time.Now().String())
	}
	return ctx.JSON(200, i)
}

func main() {
	app := faygo.New("myapp", "0.1")
	app.GET("/index/:id", new(Index))
	faygo.Run() //8080
}
```
$ curl   http://localhost:8080/index/100/
<a href="/index/100">Moved Permanently</a>.

```
package main
import (
    "fmt"
    "net/http"
)
func main() {
    http.HandleFunc("/hello/aa", func (w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Welcome to my website!")
    })
   http.ListenAndServe(":80", nil)
}

```
$ curl   http://localhost:8080/index/100/
404 page not found

faygo 和新版本golang不兼容,go1.10.1

go version
go version go1.10.1 darwin/amd64

[2018/04/23 15:40:46.768] The PID of the current process is 56453
[2018/04/23 15:40:46.776] [fay] Start build...
# errors
compile: version "go1.9" does not match go tool version "go1.10.1"
# internal/race

更新下第三方包

很多第三方包已经差的版本比较多了,希望统一更新下,修订下可能的不兼容问题

Fix Insecure Token Generation

The way IVs, keys and other tokens used for cryptographic purposes are generated by this framework fall-back to an insecure mode of generation:

e.g. https://github.com/henrylee2cn/faygo/blob/master/utils/rand.go

  • Falling back to math/rand if crypto/rand fails is dangerous: if the system CSPRNG fails, you should consider crashing, restarting or trying again (and serve the user an opaque error where possible). You cannot trust the values of math/rand to be secure for session tokens, CSRF tokens or cryptographic keys because they are deterministic and may be guessed by an attacker.
  • Conforming the generated bytes to a static alphabet introduces bias. Instead, you should just base64 (or base32, or hex) encode the generated bytes if they need to be consumed in a string context.

I've made a PR here that addresses these issues: #7

Further reading:

希望增加更多的配置和完善文档

1,文档不完善 末尾几个地址404 。 方法的文档也不详细,用起来全靠看源码猜
2,希望增加一些配置 如 json首字母自动小写或者自动驼峰 支持自定义404,500等Handle
增加日志配置和完善日志配置文档
3,感谢!

ini 加载遇到特殊字符会出错

如果配置文件里密码等信息如果包含#就会截断,导致后边的内容无法加载。解决方案是忽略掉行内的特殊字符。

ext/db/grom/config.go
cfg, err = ini.Load(DBCONFIG_FILE)

//修改为
cfg, err = ini.LoadSources(ini.LoadOptions{ IgnoreInlineComment: true, }, DBCONFIG_FILE)

Redirect 无法post值

《html》
《body onload="document.forms[0].submit()"》
《form method="post" action="https://abc.xxx.com/test"》
	《input type="hidden" name="serviceName" value="PERSONAL_REGISTER"》《/input》
《/form》
《/body》
《/html》

比如现在用ctx.Redirect(....)
重定向到这个页面
但提交后,页面并没有把这些值post过去。

Compile Error ?

$ go version
go version go1.7.4 windows/amd64
$ go get -u -v github.com/henrylee2cn/fay
github.com/henrylee2cn/fay (download)
github.com/henrylee2cn/faygo (download)
github.com/henrylee2cn/faygo
# github.com/henrylee2cn/faygo
E:\GOPATH\src\github.com\henrylee2cn\faygo\framework.go:258: srv.Shutdown undefined (type *Server has no field or method Shutdown)
E:\GOPATH\src\github.com\henrylee2cn\faygo\server.go:209: undefined: http.ErrServerClosed

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.