1
0
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:
Christoph Hartmann
2025-05-06 08:31:32 +02:00
parent c4e0fa03cd
commit 0fe93ba10e
3 changed files with 12 additions and 9 deletions

View File

@@ -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 }}

View File

@@ -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}
}
}

View File

@@ -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)