https://github.com/yakuter/optinator
Idiomatic way to fill structs with options logic
https://github.com/yakuter/optinator
go golang options struct
Last synced: 11 months ago
JSON representation
Idiomatic way to fill structs with options logic
- Host: GitHub
- URL: https://github.com/yakuter/optinator
- Owner: yakuter
- License: apache-2.0
- Created: 2022-02-13T07:48:40.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-13T09:35:23.000Z (about 4 years ago)
- Last Synced: 2025-04-13T04:52:13.943Z (11 months ago)
- Topics: go, golang, options, struct
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# optinator
Go packages are generally start with a main struct and the package initiates and fills that struct in the beginning. There are so many ways to fill that struct.
In this repo I wanted to show and idiomatic way to fill a struct. This is generally used with "options" parameters. So I called it optinator. Hope you find it helpful.
Example usage:
```go
func main() {
req := NewReq(
WithAddress("https://yakuter.com"),
WithTimeout(30*time.Second),
WithContentType("application/json"),
)
fmt.Printf("%+v", req)
}
```
Sources:
- [Different Ways to Initialize Go structs](https://asankov.dev/blog/2022/01/29/different-ways-to-initialize-go-structs/)
- [github.com/sethvargo/go-githubactions](https://github.com/sethvargo/go-githubactions/blob/main/options.go)
- [github.com/binalyze/httpreq](https://github.com/binalyze/httpreq)