Coder Social home page Coder Social logo

Comments (6)

nickcanz avatar nickcanz commented on May 28, 2024 1

Hey @leosunmo!

I would gladly accept a PR to change the signature to use string pointers, thanks for your thoughts on this.

from vulcanizer.

nickcanz avatar nickcanz commented on May 28, 2024

Thanks for this issue @leosunmo! Totally agree we should handle this.

I'm debating right now between three options:

  1. adding a new ClearClusterSetting(string) function
  2. changing the signature of SetClusterSetting(string, string) to SetClusterSetting(string, *string) so you can actually pass nil to the function
  3. add a special case for when "null" is passed to SetClusterSetting.

Right now I'm leaning towards option 3, although it's a little messy code-wise, that's the thing I would have tried intuitively as well.

from vulcanizer.

leosunmo avatar leosunmo commented on May 28, 2024

Hey @nickcanz , thanks for your reply.

Since the user is supposed to save the original setting and perform actions based on it (like resetting the settings once their operation is complete) we have to keep that in mind.

  1. This could be an OK setup, just have to keep in mind that the user is supposed to use the return of SetClusterSetting(). Here's probably how I would use it:
oldSetting, newSetting, err := client.SetClusterSetting(setting, value)
defer func() {
  if oldSetting == "" {
      ClearClusterSetting(setting)
      return
  }
  client.SetClusterSetting(setting, oldSetting)
}()
  1. If you change the signature to use pointers you'll probably have to change the return as well (so it can be used when resetting the settings using the oldSetting return). Documentation around the function also has to be very clear.
oldSetting, newSetting, err := client.SetClusterSetting(setting, valuePtr)
defer func() {
  client.SetClusterSetting(setting, oldSetting) // oldSetting has to be a pointer as well or we'll have to check if it's nil all the time.
}()
  1. This is a bit messy and confusing since the "null" is a string, not an actual JSON null value, which is not a string.
    SetClusterSetting() would also have to check if the return from Elasticsearch is ""/null and return a "null" string instead, otherwise it couldn't be used in a defer like I did above.
    If SetClusterSetting() returned a "null" string it would be quite tidy from a code perspective.
oldSetting, newSetting, err := client.SetClusterSetting(setting, value)
defer func() {
  client.SetClusterSetting(setting, oldSetting) // We don't care if oldSetting is "500" or unset/"null" because SetClusterSetting will deal with it internally.
}()

If the user wants to use the value for something other than SetClusterSetting() it might a bit confusing when the value is suddenly a "null" string however, so documentation will be important.

from vulcanizer.

leosunmo avatar leosunmo commented on May 28, 2024

I'm not quite sure which one I prefer yet. I guess if I was writing SetClusterSetting from scratch I'd probably use string pointers since it makes sense when you marshal the response from ES you'd get nil values where the value wasn't explicitly set.

from vulcanizer.

leosunmo avatar leosunmo commented on May 28, 2024

If you could have a think after the holidays I could send a PR implementing a solution.

from vulcanizer.

leosunmo avatar leosunmo commented on May 28, 2024

Will work on this when I get time

from vulcanizer.

Related Issues (19)

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.