mirror of
https://github.com/fatedier/frp.git
synced 2025-07-21 21:32:58 +07:00
health: add more ci cases and fix bugs
This commit is contained in:
@ -3,6 +3,7 @@ package mock
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -12,6 +13,36 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type HttpServer struct {
|
||||
l net.Listener
|
||||
|
||||
port int
|
||||
handler http.HandlerFunc
|
||||
}
|
||||
|
||||
func NewHttpServer(port int, handler http.HandlerFunc) *HttpServer {
|
||||
return &HttpServer{
|
||||
port: port,
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (hs *HttpServer) Start() error {
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", hs.port))
|
||||
if err != nil {
|
||||
fmt.Printf("http server listen error: %v\n", err)
|
||||
return err
|
||||
}
|
||||
hs.l = l
|
||||
|
||||
go http.Serve(l, http.HandlerFunc(hs.handler))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hs *HttpServer) Stop() {
|
||||
hs.l.Close()
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{}
|
||||
|
||||
func StartHttpServer(port int) {
|
||||
|
Reference in New Issue
Block a user