Giter VIP home page Giter VIP logo

mygin's Introduction

myGin

基于net/http编写的路由框架

介绍

模仿gin框架编写的一个极简路由框架,实现了路由管理、路由分组、中间件管理等基础功能。

example

package main


import (
	"fmt"
	"myGin"
)


func main() {
	//初始化操作:路由注册
	r:= myGin.NewEngine()
	r.Use(func(c * myGin.Context){
		fmt.Println("begin middle1")
		c.Next()
		fmt.Println("end middle1")
	})

	defaultRouters := r.Group("/")
	{
		defaultRouters.GET("/", func(c *myGin.Context) {
			c.Writer.Write([]byte("首页"))
		})
		defaultRouters.GET("/news", func(c *myGin.Context) {
			c.JSON(200, myGin.H{
				"message": "这是新闻首页",
			})
		})
	}

	apiRouters := r.Group("/api")
	{

		apiRouters.Use(func(c * myGin.Context){
			fmt.Println("begin middle2")
			c.Next()
			fmt.Println("end middle2")
		})
		apiRouters.GET("/", func(c *myGin.Context) {
			c.String(200,"我是一个api接口")
		})
		apiRouters.GET("/userlist", func(c *myGin.Context) {
			c.Writer.Write([]byte("我是一个api接口-userlist"))
		})
		play := apiRouters.Group("xx")
		play.Use(func(c * myGin.Context){
			fmt.Println("begin middle3")
			c.Next()
			fmt.Println("end middle3")
		})
		play.GET("/plist", func(c *myGin.Context) {
			c.Writer.Write([]byte("我是一个api接口-xx/plist"))
		})
	}

	//启动服务
	r.Run("127.0.0.1:8000",r)

}

```  

mygin's People

Contributors

mjiarong 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.