quickgin

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

quick-gin

License Go Report Card Build Status GoDoc GitHub release

QuickGin是为Gin打造的HTTP/2 H2C版本的扩展引擎。
HTTP/2(超文本传输协议第2版,最初命名为HTTP 2.0),简称为h2(基于TLS/1.2或以上版本的加密连接)或h2c(非加密连接),是HTTP协议的的第二个主要版本

安装

$ go get github.com/8treenet/quick-gin

使用

package main

import (
	quickgin "github.com/8treenet/quick-gin"
	"github.com/gin-gonic/gin"
)

func main() {
    //创建QuickGin
	engine := quickgin.New()
	engine.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong")
    })
    
    //engine.Run()
    engine.RunH2C()//启动 
}

客户端访问

package main

import (
	"fmt"
	"sync"
	"time"

	"github.com/8treenet/freedom/infra/requests"
)

func main() {
	round := 30
	for i := 0; i < round; i++ {
		press()
	}
}

func press() {
	requestCount := 10000
	group := sync.WaitGroup{}
	begin := time.Now()

	for i := 0; i < requestCount; i++ {
		group.Add(1)
		go func() {
			result, _ := requests.NewH2CRequest("http://127.0.0.1:8080/ping").Get().ToString()
			if result != "pong" {
				panic("ping error")
			}
			group.Done()
		}()
	}

	group.Wait()
	ms := time.Now().Sub(begin).Milliseconds()
	fmt.Printf("Request times: %d, ms time: %d \n", requestCount, ms)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QuickEngine

type QuickEngine struct {
	*gin.Engine
}

QuickEngine .

func New

func New() *QuickEngine

New .

func (*QuickEngine) RunH2C

func (engine *QuickEngine) RunH2C(addr ...string) (err error)

RunH2C .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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