Git Product home page Git Product logo

ehttp's Introduction

ehttp

#使用
go get github.com/jilin7105/ehttp
package main

import (
	"github.com/jilin7105/ehttp/eCute"
	"log"
	"net/http"
)

func main() {
    //初始化  eCute.New() 两者的区别 , Default 自带 请求信息 和 错误处理中间件
	eh := eCute.Default()
	//注册路由
	eh.GET("/hello", hello)   
	eh.GET("/hello/you", helloYou)
	eh.GET("/hai/*about", hai) //通配符 * 仅能存在于路由最后
	eh.GET("/test/:hai/about", hait)  //通配符 : 可以在路由中使用
	eh.GET("/test/:hai/test", hait)

	v1 := eh.Group("/v1") //支持分组功能
	v1.Use(func(c *eCute.C) {  //支持中间件功能
		log.Println("v1.mid")
	})

	v1.GET("/test/a", func(c *eCute.C) {
		c.JSON(http.StatusOK, eCute.H{
			"a": 2,
		})
	})
	v1.GET("/test/b", func(c *eCute.C) {
		c.String(http.StatusOK, "2222", nil)
	})
	
	err := eh.Run(":9090") //启动服务
	if err != nil {
		return
	}
	return
}

func hello(ctx *eCute.C) {
	ctx.String(200, "Hello, World!")
}
func helloYou(ctx *eCute.C) {
    
	ctx.JSON(http.StatusOK, eCute.H{
		"name": ctx.Query("name"),
		"age":  ctx.Query("age"),
	})
}

func hai(ctx *eCute.C) {

	ctx.JSON(http.StatusOK, eCute.H{
		"about": ctx.Param("about"),
	})
}
func hait(ctx *eCute.C) {

	ctx.JSON(http.StatusOK, eCute.H{
		"hai": ctx.Param("hai"),
	})
}

ehttp's People

Contributors

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