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

How to deal with https? #40

Closed
xn--jor97jsqo opened this issue Jul 3, 2014 · 5 comments
Closed

How to deal with https? #40

xn--jor97jsqo opened this issue Jul 3, 2014 · 5 comments

Comments

@xn--jor97jsqo
Copy link

have some code example?

@elithrar
Copy link
Contributor

elithrar commented Jul 3, 2014

Hi,

There's two options:

i.e. (and excuse the formatting, on my phone)

func main() {
r := web.New()
r.Use(middleware.Recovery)
r.Use(middleware.Logger)
r.Get("/", IndexHandler)

graceful.ListenAndServeTLS(":8000", "cert.pem", "key.pem", r)

}

  • Use goji.Serve() and have nginx or Apache do the SSL termination, reverse
    proxying to your Go application. This has the benefit of your Go app not
    needing to run on ports 80/443, which typically require root privileges or
    kernel capabilities.

Let me know if you need anything clarified.

On Thursday, July 3, 2014, godoc notifications@github.com wrote:

have some code example?


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

@xn--jor97jsqo
Copy link
Author

thanks

@xn--jor97jsqo
Copy link
Author

@elithrar
I write a demo code, but when go run the code, the program exit and have no error report.

package main

import (
    "net/http"
    "fmt"

    "github.com/zenazn/goji/graceful"
    "github.com/zenazn/goji/web"
    "github.com/zenazn/goji/web/middleware"
)

func main() {

    r := web.New()
    r.Use(middleware.Logger)
    r.Use(middleware.Recoverer)

    r.Get("/", IndexHandler)

    graceful.ListenAndServeTLS(":8000", "cert.pem", "key.pem", r)
}

func IndexHandler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello, %s!", "world")
}

@elithrar
Copy link
Contributor

elithrar commented Jul 3, 2014

Are you providing a certificate and key file?

Wrap graceful.ListenAndServeTLS in a log.Fatal -

log.Fatal(graceful.ListenAndServeTLS)

This should show the error if the server exits prematurely.

On Thursday, July 3, 2014, godoc notifications@github.com wrote:

@elithrar https://github.com/elithrar

I write a demo code, but when go run the code, the program exit and have
no error report.

package main

import (
"net/http"
"fmt"

"github.com/zenazn/goji/graceful"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"

)

func main() {

r := web.New()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)

r.Get("/", IndexHandler)

graceful.ListenAndServeTLS(":8000", "cert.pem", "key.pem", r)

}

func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", "world")
}


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

@defp
Copy link

defp commented Jul 3, 2014

@elithrar thanks for you answer, the code is ok, I forget generate certificate file, sorry

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

No branches or pull requests

3 participants