github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/internal/util_test/req.go (about) 1 /** 2 * Copyright 2023 CloudWeGo Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package util_test 18 19 // Req is a zero value useful request object 20 type Req struct { 21 BodyArr []byte 22 HeaderMap map[string]string 23 CookieMap map[string]string 24 QueryMap map[string]string 25 ParamMap map[string]string 26 MethodStr string 27 PathStr string 28 HostStr string 29 UriStr string 30 } 31 32 func (r Req) GetHeader(k string) string { 33 if r.HeaderMap == nil { 34 return "" 35 } 36 return r.HeaderMap[k] 37 } 38 39 func (r Req) GetCookie(k string) string { 40 if r.CookieMap == nil { 41 return "" 42 } 43 return r.CookieMap[k] 44 } 45 46 func (r Req) GetQuery(k string) string { 47 if r.QueryMap == nil { 48 return "" 49 } 50 return r.QueryMap[k] 51 } 52 53 func (r Req) GetParam(k string) string { 54 if r.ParamMap == nil { 55 return "" 56 } 57 return r.ParamMap[k] 58 } 59 60 func (r Req) GetBody() []byte { 61 return r.BodyArr 62 } 63 64 func (r Req) GetPostForm(key string) string { 65 return "" 66 } 67 68 func (r Req) GetMapBody(key string) string { 69 return "" 70 } 71 72 func (r Req) GetMethod() string { 73 return r.MethodStr 74 } 75 76 func (r Req) GetPath() string { 77 return r.PathStr 78 } 79 80 func (r Req) GetHost() string { 81 return r.HostStr 82 } 83 84 func (r Req) GetUri() string { 85 return r.UriStr 86 }