Comments (11)
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.
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.
Confirmed, it panics! See http://golang.org/src/pkg/flag/flag.go?s=22344:22405#L661.
from goji.
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.
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.
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.
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.
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.
I agree. I think that the current project structure is brilliant.
from goji.
Alright, bind
grew a bind.WithFlag()
which does what you want :)
from goji.
I like it.
from goji.
Related Issues (20)
- Use different middleware for different routes with App Engine HOT 2
- Data race when goroutines using context.Context outlive the http request HOT 2
- TLS from http.Request is nil HOT 8
- Post method with multipart/form-data encoding not work HOT 3
- returned 404 error when load js file HOT 1
- Document zenazn/goji vs goji/goji HOT 1
- wrapping HandlerType HOT 4
- Question: how to set timeout on HTTP requests HOT 8
- goji routing with react-router HOT 5
- Headers matching HOT 4
- Update ReadMe HOT 1
- Question: per-endpoint middleware HOT 5
- Does Goji 2 have Einhorn support? HOT 1
- How to use goji.ServeTLS() HOT 1
- How do I can change a variable with go command line? HOT 1
- SubRouter unexpected 404 HOT 4
- tag "v1.0" is a invalid module version HOT 5
- func Serve() have no options to disable log rquest HOT 1
- TLS context is not added to request HOT 2
- zenazn/goji or goji/goji ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goji.