http

package
v0.0.0-...-e86600b Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 10 Imported by: 0

README

http

http server and client

1. Client

import (
    "fmt"
    "github.com/Baal19905/playground/pkg/http"
)

func main() {
    client := http.NewClient(false)
    defer client.Close()
    resp, err := client.Do(
        "get",
        "http://localhost:8080",
        nil,
        nil,
    )
    
    if err != nil {
        panic(err)
    }
    fmt.Println(string(resp))
}

2. Server

import (
	"github.com/forestyc/playground/pkg/http"
	"github.com/gin-gonic/gin"
	netHttp "net/http"
)

func main() {
	// ...
	server := http.NewServer(":8080")
	server.Serve()
	server.Router.GET("/", func(c *gin.Context) {
		c.String(netHttp.StatusOK, "Hello World")
	})
	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(keepAlive bool) *Client

NewClient create http client When keepAlive is true, the connection can be reused, vice versa.

func (*Client) Close

func (c *Client) Close()

Close release http client

func (*Client) Do

func (c *Client) Do(method, url string, header map[string]string, body []byte) ([]byte, error)

Do

type Handler

type Handler interface {
	Register(*gin.Engine)
}

type Option

type Option func(*Server)

func WithHandler

func WithHandler(handlers ...Handler) Option

func WithPrometheus

func WithPrometheus(uri string) Option

type Server

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

func NewServer

func NewServer(addr string, options ...Option) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Serve

func (s *Server) Serve()

func (*Server) WithHandler

func (s *Server) WithHandler(handlers ...Handler) *Server

Jump to

Keyboard shortcuts

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