Coder Social home page Coder Social logo

Switch the usage of `UseIn` about tusd HOT 3 CLOSED

tus avatar tus commented on July 18, 2024
Switch the usage of `UseIn`

from tusd.

Comments (3)

Acconut avatar Acconut commented on July 18, 2024 1

When I first designed the StoreComposer API, I used a similar approach as you are proposing here but it had its flaws. First of all, it does not properly work if you have a struct embedding a DataStore as it will hide all additional interfaces which are implemented by the embedded struct. Here is an example to help you understand this issue: https://play.golang.org/p/Eih7d2FvqH. This behavior is un-intuitive and I was very surprised when I first encountered it. Therefore I would prefer to save people the time of catching such a bug.

Secondly, I like my code explicit. It is way more descriptive to tell exactly which extension should be used in a given composer. It makes reading, understanding and debugging easier and that's even worth the additional lines which have to be written.

Finally, a StoreComposer will be created using exactly this method (as you described) when you pass a DataStore instead of an StoreComposer in the configuration (see https://github.com/tus/tusd/blob/master/config.go#L65-L68 and https://github.com/tus/tusd/blob/master/composer.go#L29-L50). This code is not there because I like it but simply to keep it backwards-compatible because the StoreComposer was added later as I discovered weird behavior with interfaces as I described in the first paragraph.

All in all I am not an eager fan of this idea but I am looking forward to your answer.

from tusd.

oliverpool avatar oliverpool commented on July 18, 2024

The main goal is to simplify the example of the Readme:

    // A storage backend for tusd may consist of multiple different parts which
    // handle upload creation, locking, termination and so on. The composer is a
    // place where all those seperated pieces are joined together. In this example
    // we only use the file store but you may plug in multiple.
    composer := tusd.NewStoreComposer()
    compoer.UseAllExtensions(store) // instead of store.UseIn(composer)

If you think it might be a good idea, I can make a PR with this.

from tusd.

oliverpool avatar oliverpool commented on July 18, 2024

I saw your example and didn't know about this behavior: thanks for pointing it out!

Maybe you could add a link to your example (or this issue) in the source so that it appears in the godoc

    // The usage of this field is deprecated and should be avoided in favor of
    // StoreComposer (see https://github.com/tus/tusd/issues/76).

from tusd.

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.