Git Product home page Git Product logo

Comments (6)

Martin2112 avatar Martin2112 commented on May 1, 2024

Probably OK as long as you can guarantee it won't break with more realistic implementations.

Also it's potentially losing the detailed information in the error as to why the key was invalid if done via New() .

from trillian.

gdbelvin avatar gdbelvin commented on May 1, 2024

I don't think it will break realistic implementations.
I expect that key material should be available on server start and errors should be caught fairly early. Also, if we need to distinguish between multiple error cases in New we can define specific errors.

from trillian.

Martin2112 avatar Martin2112 commented on May 1, 2024

Not sure. Constructors really shouldn't be doing significant work (like reading files) and having constructors that can fail is usually an anti-pattern.

What might work is separating out all the code that decodes keys and having the PEM key manager constructor just take the keys. I don't know if this is better without trying it.

from trillian.

gdbelvin avatar gdbelvin commented on May 1, 2024

from trillian.

pphaneuf avatar pphaneuf commented on May 1, 2024

FYI, the one example of a constructor in Effective Go is one that can fail:

https://golang.org/doc/effective_go.html#composite_literals

The pattern of "constructors shouldn't be doing significant work" is mostly for languages like C++, where they can get invoked implicitly, but just about nothing is implicit in Go, so no problem, significant work and failure are totally fine, especially if it can reduce the state space of the returned object!

from trillian.

Martin2112 avatar Martin2112 commented on May 1, 2024

I sometimes think Go was designed purely to contradict every other existing language.

from trillian.

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.