server2

package module
v0.0.0-...-7558d7e Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Server

#使用方法

package main

import (
    "nqc.cn/server"
    "net/http"
    "nqc.cn/fmt"
    "nqc.cn/server/gin"
    "io/ioutil"
    "encoding/json"
    "strings"
)

 func main() {
 
    ser := server.Default()
    ser.POST("/test1",test1)
    ser.GET("/test2",test2)
    ser.RunServer()
 }
 

 
 func test2(c *gin.Context) {
 
    fmt.Println("header:",c.Request.Header)
    fmt.Println("ip:",c.Request.RemoteAddr)
 
    fmt.Println("c.Request.URL:",c.Request.URL)
    id := c.DefaultQuery("id","0")
    c.String(200,id)
 }
 
 func test(c *gin.Context) {
 
    requestbody, _ := ioutil.ReadAll(c.Request.Body)
    
    c.Request.Body.Close()
 
    var list map[string]interface{}
 
    json.Unmarshal(requestbody,&list)

    var result map[string]interface{}
 
    result = make(map[string]interface{})

    fmt.Println("result:",result)
 
    result["id"] = list["id"]
    result["status"] = `{"json":45}`
    result["test"] = 2
    c.JSON(http.StatusOK,result)
 }

客户端对接中可以采用HTTP/HTTPS来访问,同时可以采用websocket来访问,上述代码里已经添加了两个短链接同时生成了两个长链接接口。

Documentation

Index

Constants

View Source
const (
	GRACEFUL_ENVIRON_KEY    = "IS_GRACEFUL"
	GRACEFUL_ENVIRON_STRING = GRACEFUL_ENVIRON_KEY + "=1"

	DEFAULT_READ_TIMEOUT  = 60 * time.Second
	DEFAULT_WRITE_TIMEOUT = DEFAULT_READ_TIMEOUT
)

Variables

This section is empty.

Functions

func ChangeTitle

func ChangeTitle(title string)

func CreateGinConetxt

func CreateGinConetxt(value xgin.HandlerFunc) gin.HandlerFunc

func GetFullPath

func GetFullPath(path string) string

func GetTimeFromList

func GetTimeFromList(name string, l []interface{}) int64

func StripPrefix

func StripPrefix(prefix string, h http.Handler) http.Handler

func StripPrefixAdmin

func StripPrefixAdmin(prefix string, h http.Handler) http.Handler

Types

type Connection

type Connection struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*Connection) Close

func (this *Connection) Close() error

type Listener

type Listener struct {
	*net.TCPListener
	// contains filtered or unexported fields
}

func (*Listener) Accept

func (this *Listener) Accept() (net.Conn, error)

func (*Listener) GetFd

func (this *Listener) GetFd() (uintptr, error)

func (*Listener) Wait

func (this *Listener) Wait()

type XServer

type XServer struct {
	// contains filtered or unexported fields
}

func Default

func Default() *XServer

func NewServer

func NewServer(addr string, readTimeout, writeTimeout time.Duration) *XServer

new server

func (*XServer) ConnectToProcess

func (this *XServer) ConnectToProcess()

func (*XServer) DownloadFileDelegate

func (s *XServer) DownloadFileDelegate(call func(string, string, string, string))

func (*XServer) GET

func (s *XServer) GET(key string, call xgin.HandlerFunc)

func (*XServer) HandfuncWebSocket

func (s *XServer) HandfuncWebSocket(key string, call websocket.Handler)

func (*XServer) ListenAndServer

func (this *XServer) ListenAndServer() error

func (*XServer) ListenAndServerTLS

func (this *XServer) ListenAndServerTLS(certFile, keyFile string) error

func (*XServer) POST

func (s *XServer) POST(key string, call xgin.HandlerFunc)

func (*XServer) RunServer

func (this *XServer) RunServer()

func (*XServer) Server

func (this *XServer) Server() error

func (*XServer) ServerTLS

func (this *XServer) ServerTLS(srv http.Server, ln net.Listener) error

func (*XServer) SetMainRouter

func (s *XServer) SetMainRouter(mainRouter string)

func (*XServer) StartListenHandler

func (this *XServer) StartListenHandler()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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