go-murphy

module
v1.0.8-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: Apache-2.0

README

The faster and easier web framework for golang

 __  __                  _
|  \/  |_   _ _ __ _ __ | |__  _   _
| |\/| | | | | '__| '_ \| '_ \| | | |
| |  | | |_| | |  | |_) | | | | |_| |
|_|  |_|\__,_|_|  | .__/|_| |_|\__, |
                  |_|          |___/    V1.0.6,💕By Oshine
                                        leave me message-> https://space.bilibili.com/28592193
1.) Http Server + Websocket Server example ❤️ :https://gitee.com/oshine/murphy-law
2.) Murphy web framework features:
  1. Support http router && group && middleware ✅
  2. Support websocket ✅
  3. Support mysql ✅
  4. Support postgres 🪶
  5. Support sqlite 🪶
  6. Support mysql ✅
  7. Support redis ✅
  8. Support ssdb ✅
  9. Support model ✅
  10. 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", "", "")
}

Directories

Path Synopsis
def
mdb
tm

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL