github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/examples/http/http.go (about)

     1  package http
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  )
     7  
     8  type SimpleHanle struct{}
     9  
    10  func (*SimpleHanle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    11  	w.Write([]byte("Hello goloader!"))
    12  }
    13  
    14  func main() {
    15  	go func() {
    16  		panic(http.ListenAndServe(":2300", http.FileServer(http.Dir("."))))
    17  	}()
    18  	var inter http.Handler
    19  	inter = &SimpleHanle{}
    20  	listen(inter)
    21  }
    22  
    23  func listen(inter interface{}) {
    24  	mux := http.NewServeMux()
    25  	mux.Handle("/", inter.(http.Handler))
    26  	fmt.Println("start listen:9090")
    27  	panic(http.ListenAndServe(":9090", mux))
    28  }