api透传模块

func request(b *ApiBody, w http.ResponseWriter, r *http.Request) {
	var resp *http.Response
	var err error

	switch b.Method {
	case http.MethodGet:
		req, _:=http.NewRequest("GET", b.Url, nil)
		req.Header = r.Header
		resp, err= httpClient.Do(req)
		if err!=nil{
			log.Printf(err.Error())
			return
		}	
		normalResponse(w, resp)
	case http.MethodPost:
		req, _:=http.NewRequest("POST", b.Url, bytes.NewBuffer([]byte(b.ReqBody)))	
		req.Header = r.Header
		resp, err = httpClient.Do(req)
		if err!=nil {
			log.Printf(err.Error())
			return
		}
		normalResponse(w, resp)
	case http.MethodDelete:
		req, _:=http.NewRequest("Delete", b.Url, nil)
		req.Header = r.Header
		resp, err = httpClient.Do(req)
		if err!=nil{
			log.Printf(err.Error())
			return
		}	
		normalResponse(w, resp)
	default:
		w.WriteHeader(http.StatusBadRequest)
		io.WriteString(w, "Bad api request")
		return	
	}

}

  

api透传模块

上一篇:Windows窗口截图


下一篇:FastAPI