-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the cookie setting for golang code generator (#363)
- Loading branch information
1 parent
77526e2
commit e05ff4b
Showing
5 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
pkg/generator/testdata/expected_go_cookie_request_code.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
data := url.Values{} | ||
data.Set("key", "value") | ||
body := strings.NewReader(data.Encode()) | ||
|
||
req, err := http.NewRequest("GET", "https://www.baidu.com", body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
req.Header.Set("User-Agent", "atest") | ||
req.AddCookie(&http.Cookie{ | ||
Name: "name", | ||
Value: "value", | ||
}) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
panic("status code is not 200") | ||
} | ||
|
||
data, err := io.ReadAll(resp.Body) | ||
println(string(data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters