Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for supplying MIB file directly #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zaccari
Copy link

@zaccari zaccari commented Dec 21, 2020

First off, just want to say thank you for creating this library - it has helped me tremendously.

I use a small set of modules on top of a custom MIB, and it is sometimes useful for me to include the MIB files in the go binary, instead of expecting them to be available on the file system (in a container, for example). You can still load via files, if needed, this just adds a little more flexibility.

Example:

gosmi.Init()

gosmi.AppendPath("/you/can/still/load/these/mibs")

for _, moduleName := range moduleNames {
  moduleData, err := GetModuleData(moduleName)
  if err != nil {
    return err
  }

  gosmi.AddModuleFile(moduleName, moduleData)

  _, err = gosmi.LoadModule(moduleName)
  if err != nil {
    return err
  }
}

@sleepinggenius2
Copy link
Owner

Thank you for your kind words. It is really nice to see the library being put to use within the community.

I like the idea for this PR, but I think the implementation could be even simpler and more generic. The parser already supports reading from an io.Reader, so I think just adding additional functions to get and load a module from an io.Reader instead of a filename would be the more generic option that would still support your use case. That should also support the various bundler/virtual filesystem implementations out there, in addition to raw strings or byte slices. If I'm missing something else about your use case, please let me know.

@zaccari
Copy link
Author

zaccari commented Dec 22, 2020

I agree - I should have some time over the holidays to simplify things and test. Thank you for reviewing and providing feedback!

@AtakanColak
Copy link

AtakanColak commented Dec 28, 2020

I think the new embed package that will come with Go 1.16 should be used for achieving this functionality. Example code;

//go:embed my.mib
var f embed.FS
file, _ := f.Open("my.mib")
module, err := parser.Parse(file)

@sleepinggenius2
Copy link
Owner

Now that Go 1.16 has landed, can you tell me if v0.4.0 with (io/fs).FS support will meet your needs or do you still have a use case for loading directly from an io.Reader? If so, that should be implementable within your application via the smi.FS interface (=(io/fs).FS in go1.16+).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants