github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/internal/util_test/resp.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 type Resp struct { 20 Body []byte 21 StatusCode int 22 Header map[string]string 23 Cookie map[string]string 24 } 25 26 func (r *Resp) SetStatusCode(code int) error { 27 r.StatusCode = code 28 return nil 29 } 30 func (r *Resp) SetHeader(key string, val string) error { 31 if r.Header == nil { 32 r.Header = map[string]string{} 33 } 34 r.Header[key] = val 35 return nil 36 } 37 func (r *Resp) SetCookie(key string, val string) error { 38 if r.Cookie == nil { 39 r.Cookie = map[string]string{} 40 } 41 r.Cookie[key] = val 42 return nil 43 } 44 func (r *Resp) SetRawBody(body []byte) error { 45 r.Body = body 46 return nil 47 }