DEV Community

Discussion on: API Design: Optional Parameters

Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

What about a more SOLID solution that is a little bit more compromising

func ProvideOptions(os ...Option) Options  {
    o := Options{}
    for _, option := range os {
        option(&o)
    }
    return o
}

func Get(url string, o Options) (Request, error) {
      // Use immediately
        ....
}

func main()  {
    req, _ := Get("https://example.com", ProvideOptions())

}

Maybe because I like to make the Get function a little bit cleaner and not having to deal with handling Configuration

Collapse
 
samwho profile image
Sam Rose

Nice!