When web-apps are implemented in scripting languages which suffer from poor performance, it is common practice to proxy them behind a "real" web server such as nginx, and offload SSL termination, caching, handling of static components, etc to it. In Go http.ListenAndServe is an industrial strength web server, capable of gracefully handling high request rates, large numbers of simultaneous connections, http2 etc. So your Go App may as well be the web server. You are, or course, at liberty to proxy your web app behind nginx etc, like the Python and Ruby folk. But why add extra moving parts, extra configuration and extra complexity to your deployment stack?
On Monday, 20 May 2019 18:08:14 UTC+1, Tyler Compton wrote: > > Sorry I don't quite understand -- my go application IS my webserver. >> > > This is a topic that has confused me in the past. In the simple case where > you build a Go executable and get requests from it directly, your Go > application *is* your web server. However, it's common in industry to put a > system like nginx in front of your Go executable that takes care of serving > static content like images, JavaScript, CSS, and so on to the user without > consulting your Go application at all. Then, when this web server gets a > request on and endpoint that it doesn't know how to serve, like an API > call, it will forward that request to your Go application. > > With a setup like this, you're able to concentrate on writing business > logic in Go and configure caching and static resource management elsewhere. > In these cases, the application in front of your Go application is the "web > server" because it is in charge of directly serving resources to the > client. Your Go application might be called the "web application" because > it is in charge of doing application-specific tasks. It isn't strictly > necessary to adopt this format just to cache static resources, but if your > needs become more complicated in the future it might be something worth > considering :) > > >> Are you saying Go net/http is not capable of doing what I'm asking? >> >> On Sun, May 19, 2019 at 9:59 AM satyendra singh >> <satyendra...@gmail.com <javascript:>> wrote: >> > >> > Hi Tong, >> > You can use a webserver between browser and your go application which >> will take care of header modification for browser caching. >> > >> > Thanks and regards, >> > Satyendra >> > >> > On Sun, 19 May, 2019, 7:26 PM Tong Sun, <sunto...@gmail.com >> <javascript:>> wrote: >> >> >> >> Hi, >> >> >> >> How to have http.Handle / http.HandleFunc to produce static content >> that browser will use their caches without downloading every time? >> >> >> >> For a simplest http.HandleFunc, like the following, >> >> >> >> func sayHello(w http.ResponseWriter, r *http.Request) { >> >> message := "Hello " >> >> >> >> w.Write([]byte(message)) >> >> } >> >> >> >> >> >> >> >> Thet HTTP Header it produce is: >> >> >> >> HTTP/1.1 200 OK >> >> Date: Sun, 19 May 2019 13:46:32 GMT >> >> Content-Length: 6 >> >> Content-Type: text/plain; charset=utf-8 >> >> >> >> >> >> I.e., the "Date:" part is changing all the time, even if I've added a >> "last-modified" Header field. >> >> >> >> What's the solution? Thx >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/CAMmz1OeBW5rp4RcfYtC%3Dk%3DpeX%3DdizF5G9Gv0Y1dgm5%2BG3%3DZBYA%40mail.gmail.com >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0ae68bf2-5a5a-42e1-97e7-dbc12c515887%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.