GithubHelp home page GithubHelp logo

Add monoids for options about connect-go HOT 4 CLOSED

connectrpc avatar connectrpc commented on August 27, 2024
Add monoids for options

from connect-go.

Comments (4)

bufdev avatar bufdev commented on August 27, 2024

What is the purpose of this? I don't immediately get it

from connect-go.

akshayjshah avatar akshayjshah commented on August 27, 2024

Imagine your organization (like Buf!) has a standard collection of options that you'd like every handler, client, or both to use. Without this, you end up with a fairly unpleasant set of APIs: StandardClientOptions() []connect.ClientOption, etc., and users are constantly appending to slices and splatting them again.

client, err := NewFooClient(...,
  append(someorg.StandardClientOptions(),
    SomeSpecificOption(),
    SomeOtherOneOffOption(),
  )...,
)

With these functions, life's a bit nicer. someorg.StandardClientOptions can bundle a bunch of options into a single connect.ClientOption, and the user code ends up like this:

client, err := NewFooClient(...,
  someorg.StandardClientOptions(),
  someorg.UnusualOption(),
  MyOneOffOption(),
)

Ultimately, it's convenient for users to be able to make a single option have multiple effects. More or less, this is the same reason your proposal to build a multi-plugin for protoc/buf is nicer than forcing every tool to take a list of plugins to generate into the same directory.

from connect-go.

akshayjshah avatar akshayjshah commented on August 27, 2024

Examples from other packages I've worked on:

Both of those options ended up pretty widely used, and the fx one in particular was a cornerstone of the whole ecosystem.

from connect-go.

bufdev avatar bufdev commented on August 27, 2024

I'm not sure this will be as used in the connect world and it just adds to the number of types, but you feel strongly about it and it's fine with me. I might say that WithOptions confuses me a bit as opposed to something signaling this is a union of options like (and not suggesting this directly) but MultiOption

from connect-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.