Code Monkey home page Code Monkey logo

gos's Introduction

狗子

  • 不错这个webframework 就是叫狗子,我的golang 成长之路

start

   package main
   import "github.com/qlu1990/gos"
   
   func hello(c *gos.Context) {
	fmt.Fprintln(c.ResponseWriter, "hello world")
    }


   func main(){
       r := gos.NewGos()
       r.AddGet("/hello", hello)
       r.Run(":8000") //runing listen port 8000
   }
  

路由

  • 路由使用map 可以优化 可以参考gin 使用属树(已经实现)
  • 路由还不能支持路径中带参数 (已实现)

路由函数

    type HandlerFunc func(*Context)
    r := gos.NewGos()
    r.AddGet(url string ,f HandlerFunc) // 路由get
    r.AddPost(url string ,f HandlerFunc) // 路由post
    r.AddHead(url string ,f HandlerFunc) // 路由head
    r.AddDelete(url string ,f HandlerFunc) // 路由delete
  • 请求路径中带参数
  func GetPerson(c *gos.Context) {
  name := c.Param("name")
  gos.Response(c.ResponseWriter,"hello "+name, http.StatusOK)
  }
  func main(){
  r := gos.NewGos()
  r.AddGet("/hello/:name",GetPerson)
  }
  

Middleware

实现数据结构

  • Name 中间件名称不能重名
  • HandlerFunc 被调用调用函数
    type Middleware struct {  
	Name        string
	HandlerFunc HandlerFunc      
    }
    
    type HandlerFunc func(*Context)

使用方法

以glog 为例

    r := gos.NewGos()
   var Mlog = Middleware{
	Name: "log",
	HandlerFunc: func(c *Context) {
		Glog.Info("Request : ", c.Request.Method, " ", c.Request.RequestURI)
	},
    }
   r.Use(Mlog)

#日志模块

使用

   r := gos.NewGos()
   r.Info("info log")
   r.Debug("debug log")
   r.Error("error log")
   r.Fatal("fatal log")
   r.Warn("warn log")

案例

案例 gos-example

email: [email protected]

gos's People

Contributors

qlu1990 avatar

Stargazers

 avatar

Watchers

 avatar

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.