The faster and easier web framework for golang
__ __ _
| \/ |_ _ _ __ _ __ | |__ _ _
| |\/| | | | | '__| '_ \| '_ \| | | |
| | | | |_| | | | |_) | | | | |_| |
|_| |_|\__,_|_| | .__/|_| |_|\__, |
|_| |___/ V1.0.6,💕By Oshine
leave me message-> https://space.bilibili.com/28592193
2.) Murphy web framework features:
- Support http router && group && middleware ✅
- Support websocket ✅
- Support mysql ✅
- Support postgres 🪶
- Support sqlite 🪶
- Support mysql ✅
- Support redis ✅
- Support ssdb ✅
- Support model ✅
- Support model auto generate ✅
Http Server Demo🍔:
运行以下代码,访问浏览器:http://127.0.0.1:8000/api/home/index
package main
import (
"gitee.com/oshine/go-murphy/core"
"gitee.com/oshine/go-murphy/core/text"
"github.com/valyala/fasthttp"
"log"
)
type HomeController struct {
}
// Index 首页
func (mc *HomeController) Index(ctx *fasthttp.RequestCtx) error {
method := string(ctx.Request.Header.Method())
log.Println(method)
if text.InArray(method, []string{"GET", "POST", "PUT", "DELETE"}) {
ctx.Response.SetBodyString("Hello World")
return nil
}
ctx.Response.SetBodyString("Not Support Method:" + method)
return nil
}
func main() {
svr := core.Server{}
svr.Http().
Group("/api", func(group *core.SvrGroup) {
//group.MiddleWare(m.Auth)
//group.Auth("Auth")
//
//group.Home("/home/index")
group.Bind(
&HomeController{},
//&OtherController{},
)
}).RunTLS("127.0.0.1:8000", "", "")
}
Websocket Server Demo🍔:
package main
import (
"gitee.com/oshine/go-murphy/core"
"github.com/fasthttp-contrib/websocket"
)
func WsV1(c *websocket.Conn) error {
err := c.WriteMessage(websocket.TextMessage, []byte("Hello World!"))
if err != nil {
return err
}
return nil
}
func main() {
svr := core.Server{}
svr.Ws().
//MiddleWare(WsV1).
Router("/ws-v1", WsV1).
//Router("/ws-v2", ws.WsV2).
RunTLS("127.0.0.1:8006", "", "")
}