https://github.com/3n0ugh/curl2struct
✨ Easily convert curl command to Golang struct
https://github.com/3n0ugh/curl2struct
curl curl2go curl2golang curl2json curl2struct
Last synced: 6 months ago
JSON representation
✨ Easily convert curl command to Golang struct
- Host: GitHub
- URL: https://github.com/3n0ugh/curl2struct
- Owner: 3n0ugh
- Created: 2024-01-13T10:49:01.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-13T13:30:01.000Z (about 2 years ago)
- Last Synced: 2025-07-01T19:08:31.371Z (7 months ago)
- Topics: curl, curl2go, curl2golang, curl2json, curl2struct
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# curl2struct
`curl2struct` is a tool designed to convert curl commands into equivalent Golang structs.
This can be particularly useful when working on Golang projects and needing to translate HTTP requests from curl commands into Go code.
## Installation
To install `curl2struct`, you can use `go get`:
```bash
go get -u github.com/3n0ugh/curl2struct
```
## Usage
```go
package main
import (
"fmt"
"github.com/3n0ugh/curl2struct"
"log"
)
var curl = `curl 'https://github.com/3n0ugh/curl2struct/tree-commit-info/main' \
-H 'authority: github.com' \
-H 'accept: application/json' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'content-type: application/json' \
-d '{"a": "b"}'
--compressed`
func main() {
c, err := curl2struct.NewCurl(curl)
if err != nil {
log.Fatal(err)
}
fmt.Println(c)
/*
URL: https://github.com/3n0ugh/curl2struct/tree-commit-info/main
Method: POST
Headers: map[Accept:[application/json] Accept-Language:[en-US,en;q=0.9] Authority:[github.com] Content-Type:[application/json]]
Body: {"a": "b"}
*/
}
```
* The NewCurl(curl string) function returns the CURL model.
```go
type CURL struct {
URL string
Method string
Headers http.Header
Body []byte
}
```