Git Product home page Git Product logo

Comments (11)

elithrar avatar elithrar commented on July 28, 2024

By override do you mean "specify the port in the application itself" or
"use the flag in my own package"?

On Sunday, July 20, 2014, Jesús García Crespo [email protected]
wrote:

bind is fantastic, but it defines a -bind cli flag even when you are not
making use of it. I'm aware that people out there may be relying on that
specific behaviour but it would be nice to have a mechanism to override it,
any ideas?


Reply to this email directly or view it on GitHub
#47.

from goji.

sevein avatar sevein commented on July 28, 2024

I meant the former, in my particular case I just don't want to use -bind right now. But I guess redefinition of the flag wouldn't be possible neither.

from goji.

sevein avatar sevein commented on July 28, 2024

Confirmed, it panics! See http://golang.org/src/pkg/flag/flag.go?s=22344:22405#L661.

from goji.

elithrar avatar elithrar commented on July 28, 2024

You can use https://godoc.org/github.com/zenazn/goji/graceful#ListenAndServe to
specify a listening port.

i.e.

r := web.New()
r.Use(middleware.Recoverer)
// etc...
r.Get("/", ShowIndex)

graceful.ListenAndServe(":8000", r)

This is exactly what I do.

On Sunday, July 20, 2014, Jesús García Crespo [email protected]
wrote:

I meant the former, in my particular case I just don't want to use -bind
right now. But I guess redefinition of the flag wouldn't be possible
neither.


Reply to this email directly or view it on GitHub
#47 (comment).

from goji.

sevein avatar sevein commented on July 28, 2024

Yeah, I'm doing something similar. I'm assuming you also make use of the -bind flag. I think it's a bit too invasive... e.g. let's say that you don't want to provide that option in your command line tool because your configuration loading mechanism takes care of the address to bind on somewhere else.

$ go run server.go -help
Usage of /h/u/g/bin/server
  -bind=":8000": Address to bind on. If this value has a colon, as in ":8000" or
        "127.0.0.1:9001", it will be treated as a TCP address. If it
        begins with a "/" or a ".", it will be treated as a path to a
        UNIX socket. If it begins with the string "fd@", as in "fd@3",
        it will be treated as a file descriptor (useful for use with
        systemd, for instance). If it begins with the string "einhorn@",
        as in "einhorn@0", the corresponding einhorn socket will be
        used. If an option is not explicitly passed, the implementation
        will automatically select among "einhorn@0" (Einhorn), "fd@3"
        (systemd), and ":8000" (fallback) based on its environment.

from goji.

elithrar avatar elithrar commented on July 28, 2024

I don't use the -bind flag myself.

Using graceful.ListenAndServe to explicitly specify a port does not
configure the -bind flag (it's only provided when you use the top-level
Goji package):

./wwg2 -help
Usage of ./wwg2:
-createadmin=false: Create a new administrative user
-createdb=false: Create the database schema.
-email="": Email address
-name="": Full name

Notice that -bind isn't an available option.

On Sunday, July 20, 2014, Jesús García Crespo [email protected]
wrote:

Yeah, I'm doing something similar. I'm assuming you also make use of the `
-bind flag. I think it's a bit too intrusive... e.g. let's say that you
don't want to have that option in your command line because your
configuration loading mechanism is different.

$ go run server.go -help
Usage of /h/u/g/bin/server
-bind=":8000": Address to bind on. If this value has a colon, as in ":8000" or
"127.0.0.1:9001", it will be treated as a TCP address. If it
begins with a "/" or a ".", it will be treated as a path to a
UNIX socket. If it begins with the string "fd@", as in "fd@3",
it will be treated as a file descriptor (useful for use with
systemd, for instance). If it begins with the string "einhorn@",
as in "einhorn@0", the corresponding einhorn socket will be
used. If an option is not explicitly passed, the implementation
will automatically select among "einhorn@0" (Einhorn), "fd@3"
(systemd), and ":8000" (fallback) based on its environment.


Reply to this email directly or view it on GitHub
#47 (comment).

from goji.

sevein avatar sevein commented on July 28, 2024

Oh, I see! I was importing goji because of DefaultMux but I guess I can just build my own Mux object. Thank you!

Should I close this issue?

from goji.

zenazn avatar zenazn commented on July 28, 2024

So like elithrar mentioned, the project is structured in such a way that using the top-level goji package gives you a really nice out-of-box experience with reasonable defaults, and the sub-projects provide more API flexibility for people who have either specific needs or simply don't like the defaults I've chosen.

I've considered making bind not install the flag by default, instead exposing a function that adds the flag for you (that the top-level goji would call, similar to what we do now for graceful.HandleSignals()). The primary motivation here would be that bind has grown some moderately interesting logic for parsing "bind strings," and it'd be a pity if people had to inline that logic just to avoid the global flag pollution. I think this would allow you to do what you want to do? (i.e., you'd still need to create your own mux, etc. etc., but at least you'd be able to use the same bind string syntax)

from goji.

sevein avatar sevein commented on July 28, 2024

I agree. I think that the current project structure is brilliant.

from goji.

zenazn avatar zenazn commented on July 28, 2024

Alright, bind grew a bind.WithFlag() which does what you want :)

from goji.

sevein avatar sevein commented on July 28, 2024

I like it.

from goji.

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.