mirror of
https://github.com/ggicci/httpin.git
synced 2025-11-06 08:59:26 +02:00
use own struct for testing
simplified code for parsing to kvs updated workflow
This commit is contained in:
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
run: make test/cover
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
name: codecov-umbrella
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"github.com/ggicci/httpin/core"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/ggicci/httpin/core"
|
||||
)
|
||||
|
||||
type HttpMuxVarsFunc func(*http.Request) map[string]string
|
||||
@@ -30,10 +28,10 @@ func (mux *httpMuxVarsExtractor) Execute(rtm *core.DirectiveRuntime) error {
|
||||
req := rtm.GetRequest()
|
||||
kvs := make(map[string][]string)
|
||||
|
||||
for _, value := range strings.Split(req.Pattern, "/") {
|
||||
if strings.HasPrefix(value, "{") && strings.HasSuffix(value, "}") {
|
||||
value = strings.TrimSuffix(strings.TrimPrefix(value, "{"), "}")
|
||||
kvs[value] = []string{req.PathValue(value)}
|
||||
for _, key := range rtm.Directive.Argv {
|
||||
value := req.PathValue(key)
|
||||
if value != "" {
|
||||
kvs[key] = []string{value}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,17 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type HttpMuxPathInput struct {
|
||||
Username string `in:"path=username"`
|
||||
PostID int64 `in:"path=pid"`
|
||||
}
|
||||
|
||||
func TestUseHttpMux(t *testing.T) {
|
||||
httpinIntegration.UseHttpMux("path")
|
||||
|
||||
srv := http.NewServeMux()
|
||||
srv.HandleFunc("/users/{username}/posts/{pid}", func(w http.ResponseWriter, r *http.Request) {
|
||||
param := &GetPostOfUserInput{}
|
||||
param := &HttpMuxPathInput{}
|
||||
core, err := httpin.New(param)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user