FAQ
Simple question:

Can I use Go (exes) with an existing Apache sever to serve dynamic content?
For clarity, assume the scenario of a hosted website on a random host
service, and no net/http package being used to start a Go http server.

A tutorial maybe, a real world example, that would be nice.
Thanks.

--

Search Discussions

  • Bryanturley at Nov 1, 2012 at 7:01 pm
    Haven't done that in forever.

    http://httpd.apache.org/docs/2.2/howto/cgi.html#writing

    This isn't the fastest way, but it might get you thinking...
    You should read up on security problems this may cause you as well.

    Why not just use net/http ?

    --
  • Dustin at Nov 1, 2012 at 7:15 pm

    On Thursday, November 1, 2012 11:52:45 AM UTC-7, Dumitru Ungureanu wrote:
    Simple question:

    Can I use Go (exes) with an existing Apache sever to serve dynamic content?
    For clarity, assume the scenario of a hosted website on a random host
    service, and no net/http package being used to start a Go http server.

    A tutorial maybe, a real world example, that would be nice.
       You have at least three options:

       1. Make a standalone web server that runs forever and proxy through it.
       2. Make a cgi.
       4. Use something like my go-stdinweb on a proxy.

    go-stdinweb is mostly useful for when you want a cgi-type model, but you
    don't want to run it on the same web server, as the same user ID, or you
    just can't use CGI. It runs a web sever out of inetd (for example).

    I find #1 easiest (but I also don't use Apache very much at all).

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 7:37 pm
    Thanks for the answers.

    My scenario is this, again: on an Economy account (4-5$/month), is Go
    viable?
    I mean, net/http proxy seems like the logical choice, but what are the
    dependencies, if any, or the special rights needed, if any?

    --
  • Dustin at Nov 1, 2012 at 7:53 pm

    On Thursday, November 1, 2012 12:37:00 PM UTC-7, Dumitru Ungureanu wrote:
    Thanks for the answers.

    My scenario is this, again: on an Economy account (4-5$/month), is Go
    viable?
    I mean, net/http proxy seems like the logical choice, but what are the
    dependencies, if any, or the special rights needed, if any?
       The label or price of your hosting solution has little to do with
    applicability of go. If you want CGIs, go would be better at it than most
    alternatives. If you can write server itself in go, it'd probably work
    even better. Need more details there.

       I've been running go hosted at Google App Engine for nearly six months.
      Works pretty economically there.

    --
  • Bryanturley at Nov 1, 2012 at 8:02 pm

    My scenario is this, again: on an Economy account (4-5$/month), is Go
    viable?
    I mean, net/http proxy seems like the logical choice, but what are the
    dependencies, if any, or the special rights needed, if any?
    Define economy account?

    Sounds like you don't have a lot of experience working on the server side
    of http.
    I suggest you try setting one up on your local network and experiment.


    --
  • Bryanturley at Nov 1, 2012 at 8:05 pm
    Go is not viable if you cannot run native code. Some of those hosting
    companies will run python/php scripts but not native code you will have to
    talk to them about it.
    I don't think I have ever seen a $5 plan at any provider that does allow
    native binaries, though I haven't tried to find a non vps'ed host since the
    early 2000s.


    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:00 pm
    I was merely mentioning the cheap hosting plan to send the proper message
    about my intentions: target clients with cheap hosting accounts on third
    party hosting servers like FatCow. As you know, there are limitations to
    what you can do with these accounts, files, environments etcetera.

    So, again, is Go viable as a backend app in this case? How exactly.
    Thanks.

    --
  • Dustin at Nov 1, 2012 at 8:06 pm

    On Thursday, November 1, 2012 1:00:20 PM UTC-7, Dumitru Ungureanu wrote:
    I was merely mentioning the cheap hosting plan to send the proper message
    about my intentions: target clients with cheap hosting accounts on third
    party hosting servers like FatCow. As you know, there are limitations to
    what you can do with these accounts, files, environments etcetera.

    So, again, is Go viable as a backend app in this case? How exactly.
       Well, I don't actually know much about those. I do know some about go,
    though.

       The only issue you might run into is that the file size will be larger.
      Your programs will probably be faster and more capable than scripting
    equivalents. If the file size isn't an issue, you'll have a significantly
    easier time distributing and running your application.

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:04 pm
    Actually, I do have experience on the server side. It seems your not
    familiar with third party web hosting plans and policies.

    --
  • Bryanturley at Nov 1, 2012 at 8:10 pm

    On Thursday, November 1, 2012 3:04:14 PM UTC-5, Dumitru Ungureanu wrote:
    Actually, I do have experience on the server side. It seems your not
    familiar with third party web hosting plans and policies.
    lol, sorry if I sounded insulting was trying to help ;)


    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:12 pm
    I appreciate that :)

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:08 pm
    OK. Maybe someone else has more insight to this particular problem.
    Thanks.

    --
  • Dustin at Nov 1, 2012 at 8:16 pm

    On Thursday, November 1, 2012 1:08:45 PM UTC-7, Dumitru Ungureanu wrote:
    OK. Maybe someone else has more insight to this particular problem.
       I think you're in the wrong place. Your question seems to be, "Do cheap
    hosting companies allow users to run native binaries/cgis/custom web
    servers?" I don't think we can answer that here other than to let you know
    the few places where we do have the servers running (for me, GAE, FreeBSD
    9/amd64, OS X/amd64, Linux/{amd64,386,ARM5,ARM11}, Windows).

       Beyond that, you need to find out what the limitations imposed by the
    hosting providers you're targeting. That's a question for them.

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:18 pm
    I thought I try here too, maybe there were some other more Go experienced
    folks tackle this one ahead.

    --
  • Bryanturley at Nov 1, 2012 at 8:20 pm

    On Thursday, November 1, 2012 3:18:17 PM UTC-5, Dumitru Ungureanu wrote:
    I thought I try here too, maybe there were some other more Go experienced
    folks tackle this one ahead.
    What Dustin is trying to say is that this is not a Go problem, this is a
    Hosting provider problem.
    You would have to see the policies on the individual providers sites.

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:25 pm
    And what I'm trying to say is that maybe someone else involved with Go has
    gone through all of this and knows to give me a tried, real world answer :)

    --
  • Dustin at Nov 1, 2012 at 8:29 pm

    On Thursday, November 1, 2012 1:25:25 PM UTC-7, Dumitru Ungureanu wrote:
    And what I'm trying to say is that maybe someone else involved with Go has
    gone through all of this and knows to give me a tried, real world answer :)
       I did. Works great on GAE, AWS and Linode and a bunch of misc machines
    I've got. I indirectly use go on heroku and probably a few other services.

    --
  • Dumitru Ungureanu at Nov 1, 2012 at 8:36 pm
    Sorry, I meant a real world example for my particular question. I'm not
    asking if net/http works, obviously it does.

    I'm rather asking if Go is viable as a webdev backend, in a cheap third
    party common host environment (4-5$, Apache...)? Has anyone actually
    managed serving dynamic content with Go (exes) under such conditions?

    Thanks.

    --
  • Tomwilde at Nov 1, 2012 at 10:16 pm
    The answer is no. On an average hostgator-style hosting account there's no way you'll get to run native code.

    It would be interesting to build a sandboxed (like the playground) Go environment for hosting providers though. The risks are high though.

    --
  • Bryanturley at Nov 2, 2012 at 12:51 am

    On Thursday, November 1, 2012 5:16:17 PM UTC-5, tomwilde wrote:
    The answer is no. On an average hostgator-style hosting account there's no
    way you'll get to run native code.

    It would be interesting to build a sandboxed (like the playground) Go
    environment for hosting providers though. The risks are high though.
    I think he is going to ask it till he gets the answer he wants, denying
    reality all the way.


    --
  • Dumitru Ungureanu at Nov 2, 2012 at 5:35 am

    On Friday, November 2, 2012 2:51:36 AM UTC+2, bryanturley wrote:


    I think he is going to ask it till he gets the answer he wants, denying
    reality all the way.
    You seem to be finding a way to turn the conversation into personal attacks
    pretty much every thread I've seen you respond to. Is that a gift you've
    come by naturally or are you just trying too hard? Oh, and don't bother
    telling me to go for a walk or go pick a flower or something, 'mkay? It's
    you, it's not me. ;)

    --
  • Bryanturley at Nov 2, 2012 at 7:17 am

    On Friday, November 2, 2012 12:35:10 AM UTC-5, Dumitru Ungureanu wrote:
    On Friday, November 2, 2012 2:51:36 AM UTC+2, bryanturley wrote:


    I think he is going to ask it till he gets the answer he wants, denying
    reality all the way.
    You seem to be finding a way to turn the conversation into personal
    attacks pretty much every thread I've seen you respond to. Is that a gift
    you've come by naturally or are you just trying too hard? Oh, and don't
    bother telling me to go for a walk or go pick a flower or something, 'mkay?
    It's you, it's not me. ;)
    You should see some of the other forums I post on. I am fairly certain I
    made this one gentlemans head explode with only the power of my typing!



    --
  • Gustavo Niemeyer at Nov 3, 2012 at 1:28 pm

    On Fri, Nov 2, 2012 at 6:35 AM, Dumitru Ungureanu wrote:
    You seem to be finding a way to turn the conversation into personal attacks
    I agree. The question is totally fine, and there's no reason to be
    unfriendly like that. This is also the right forum for asking it.

    The short answer is that yes, it's certainly possible to run Go on
    budget servers. For simpler things, I run FastCGI programs on
    DreamHost, for example. These days you can also get a VM for about $5
    without searching too much, and run a full blown Go http server there.
    Have a look at http://www.lowendbox.com for some ideas (of course, you
    get what you pay for).

    For how to write the program, have a look at the documentation for the
    net/http, net/http/cgi, and net/http/fcgi packages to get good
    information on the APIs. Google will also show you examples of Go
    programs on the first page (search for "golang fastcgi" or "golang
    cgi").

    If you try things out, and you cannot get details working, please mail
    what you attempted to the list. I'm sure some friendly folks will help
    you out.


    gustavo @ http://niemeyer.net

    --
  • Bryanturley at Nov 3, 2012 at 4:06 pm

    On Saturday, November 3, 2012 8:28:11 AM UTC-5, Gustavo Niemeyer wrote:
    On Fri, Nov 2, 2012 at 6:35 AM, Dumitru Ungureanu wrote:
    You seem to be finding a way to turn the conversation into personal
    attacks

    I agree. The question is totally fine, and there's no reason to be
    unfriendly like that. This is also the right forum for asking it.
    Read the entire thread again. Two separate people give him the correct
    answer, and all he can say is he wants "more Go experienced folks"
    Now I can't speak for Dustin but I know there are many many here that are
    more experienced than me.
    But that doesn't make us wrong, he just wants someone to hold his hand all
    the way, which would in the end be bad for him since he won't learn
    anything.

    Build a man a fire he is warm for a day.
    Light a man on fire he is warm for the rest of his life.

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 5:28 pm
    *@bryanturley

    Thank you for all your interest in this thread and all your answers so far.
    If you have *a more elaborate *technical* answer, a real life example, I
    certainly would appreciate that.

    Otherwise please just stop talking about me being this and that or wanting
    this and that.
    I'm sure you've got better things to do. Go do them ;)

    Thanks you.*
    *

    --
  • Bryanturley at Nov 3, 2012 at 7:03 pm

    On Saturday, November 3, 2012 12:28:52 PM UTC-5, Dumitru Ungureanu wrote:
    *@bryanturley

    Thank you for all your interest in this thread and all your answers so
    far.
    If you have *a more elaborate *technical* answer, a real life example, I
    certainly would appreciate that.

    Otherwise please just stop talking about me being this and that or wanting
    this and that.
    I'm sure you've got better things to do. Go do them ;)

    Thanks you.*
    *

    Oh trust me I will never try to help you again.


    --
  • Dumitru Ungureanu at Nov 3, 2012 at 7:09 pm
    It's your choice, but I believe that will work fine too for both of us. All
    the best to you.
    On Saturday, November 3, 2012 9:03:44 PM UTC+2, bryanturley wrote:

    Oh trust me I will never try to help you again.
    --
  • Dustin at Nov 3, 2012 at 7:06 pm

    On Saturday, November 3, 2012 10:28:52 AM UTC-7, Dumitru Ungureanu wrote:


    *If you have *a more elaborate *technical* answer, a real life example, I
    certainly would appreciate that.

       Perhaps I failed to understand what technical answers you're seeking.
    This is the exact question you asked:

         "on an Economy account (4-5$/month), is Go viable?"

       Go runs pretty on pretty much anything you're going to find, but whether
    or not it's viable for a given account at some arbitrary hosting is not
    something anyone other than your hosting facility can answer.

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 7:12 pm

    On Saturday, November 3, 2012 9:06:49 PM UTC+2, Dustin wrote:
    Perhaps I failed to understand what technical answers you're seeking.
    This is the exact question you asked:

    "on an Economy account (4-5$/month), is Go viable?"

    To be a bit more precise, this is my question/ask, from the first post:

    On Thursday, November 1, 2012 8:52:45 PM UTC+2, Dumitru Ungureanu
    wrote:Simple question:

    Can I use Go (exes) with an existing Apache sever to serve dynamic content?
    A tutorial maybe, a real world example, that would be nice.

    --
  • Dustin Sallings at Nov 3, 2012 at 7:39 pm
    Dumitru Ungureanu <itmitica@gmail.com>
    writes:
    To be a bit more precise, this is my question/ask, from the first
    post:

    On Thursday, November 1, 2012 8:52:45 PM UTC+2, Dumitru Ungureanu
    wrote:Simple question:

    Can I use Go (exes) with an existing Apache sever to serve dynamic
    content?
    A tutorial maybe, a real world example, that would be nice.
       OK, you've got pointers to CGI documentation, FCGI documentation, wsgi
    wrappers, and some mentions of GAE and heroku. Much of that was before
    the "can I run on cheap hosting" question, so I misunderstood your
    intentions and assumed you wanted to take the question down a
    non-technical path.

       Perhaps it'd be best to state your complete goal, otherwise people
    wishing to help you will just continue to make bad assumptions as to
    what it is.

       If you're looking for cheap hosting, GAE is not going to cost you $4
    per month if your app isn't very popular. If you don't want to use GAE,
    then you could list your requirements if they don't match suggestions
    you've already received (Gustavo pointed you to Dreamhost, Lowend Box
    and implied there were many other alternatives).

       If you want to know how to integrate with the solution you've chosen,
    ask specific questions about what you've run into that's blocking you.
    You've decided to do CGI and don't understand something about the CGI
    module. Show the code and ask how to help. If you're having trouble
    with FastCGI at some provider, be specific about the trouble you're
    having. Do you understand FastCGI at all? Do you understand it really
    well, but don't understand the docs for go? Do you understand the docs,
    but don't find things are working as documented? Maybe you want to do
    the proxying mechanism like I use to run all my small apps, but you
    don't know how to configure the nginx the service provider offers and
    need help.

       Lots of people are trying to help you, but we're all just guessing
    what problems you're running into and it seems to be frustrating you as
    much as anyone else.

    -- dustin

    --
  • Althalus87 at Nov 2, 2012 at 2:08 am

    On Friday, November 2, 2012 7:36:13 AM UTC+11, Dumitru Ungureanu wrote:
    Sorry, I meant a real world example for my particular question. I'm not
    asking if net/http works, obviously it does.

    I'm rather asking if Go is viable as a webdev backend, in a cheap third
    party common host environment (4-5$, Apache...)? Has anyone actually
    managed serving dynamic content with Go (exes) under such conditions?

    Thanks.
    Traditional shared hosting providers? The answer is almost guaranteed to be
    no.

    If you're willing to look outside the box, and maybe add a few dollars to
    your monthly spend, take a look at webfaction. Their setup is, completely
    atypical of what you'd normally get in a shared hosting environment, but it
    can do what you want. I'm running one Go toy project under my webfaction
    account successfully.


    You could also maybe try hosting on heroku, I believe they have a build
    pack for go.

    ~Justin

    --
  • Dumitru Ungureanu at Nov 2, 2012 at 5:44 am
    @tom, @Justin:

    Got it. Thanks.

    On a personal note, it seems that while Go is a fun an interesting language
    to learn, the minimal requirements for successfully running Go in *my* real
    world seem to go way beyond Python's: x64 machines, to be on the safe side
    etcetera. So, *for me*, at least at this moment, Python seems like a better
    investment.

    --
  • David Anderson at Nov 2, 2012 at 5:47 am

    On Thu, Nov 1, 2012 at 10:44 PM, Dumitru Ungureanu wrote:

    @tom, @Justin:

    Got it. Thanks.

    On a personal note, it seems that while Go is a fun an interesting
    language to learn, the minimal requirements for successfully running Go in
    *my* real world seem to go way beyond Python's: x64 machines, to be on the
    safe side etcetera. So, *for me*, at least at this moment, Python seems
    like a better investment.

    Sounds good. Have fun with Python, it's a fun language. Come by again some
    time, maybe Go will be a better fit for what you need.

    - Dave

    --
  • Dustin at Nov 2, 2012 at 5:56 am

    On Thursday, November 1, 2012 10:44:01 PM UTC-7, Dumitru Ungureanu wrote:
    @tom, @Justin:

    Got it. Thanks.

    On a personal note, it seems that while Go is a fun an interesting
    language to learn, the minimal requirements for successfully running Go in
    *my* real world seem to go way beyond Python's: x64 machines, to be on the
    safe side etcetera. So, *for me*, at least at this moment, Python seems
    like a better investment.
       My primary web server at home is a power-brick sized 32-bit ARM5 box
    running web server software I wrote in go. It never goes more than a few
    seconds without servicing a web hit. It's currently sitting under 9MB RSS
    with about 9 days of uptime (presumably the last time my gf accidentally
    turned off the power strip it's connected to). I typed "python" on my mac
    and then "import cgi" and it's sitting at 8.5MB RSS.

       Go ahead and use whatever works for you. You've still given no
    indication whatsoever what you want from this group and people did spend
    time trying to extract that information out of you and figure out how they
    could help. If you're just looking for a reason not to use go, someone
    could possibly help you with that, too. Unfortunately, I don't have an
    answer to why you wouldn't.

    --
  • Mattn at Nov 2, 2012 at 7:20 am
    use CGI or uWSGI

    https://github.com/mattn/go-uwsgi

    You can use mod_uwsgi/apache with this. :)
    On Friday, November 2, 2012 3:52:45 AM UTC+9, Dumitru Ungureanu wrote:

    Simple question:

    Can I use Go (exes) with an existing Apache sever to serve dynamic content?
    For clarity, assume the scenario of a hosted website on a random host
    service, and no net/http package being used to start a Go http server.

    A tutorial maybe, a real world example, that would be nice.
    Thanks.
    --
  • Dumitru Ungureanu at Nov 2, 2012 at 7:36 am
    @mattn
    Sounds promising. I'll check it out. Thanks.

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 9:38 am

    On Friday, November 2, 2012 9:20:22 AM UTC+2, mattn wrote:

    use CGI or uWSGI

    https://github.com/mattn/go-uwsgi

    You can use mod_uwsgi/apache with this. :)
    Can you provide me with a more detailed info on the whole setup and running
    process, please? Thanks.

    --
  • André Moraes at Nov 2, 2012 at 1:36 pm
    If you can configure your apache to use FCGI protocol, Go has a
    package in stdlib that can be used.

    Just check:

    http://golang.org/pkg/net/http/fcgi/

    It works almost the same way that net/http works but uses FCGI instead of HTTP.
    On Thu, Nov 1, 2012 at 4:52 PM, Dumitru Ungureanu wrote:
    Simple question:

    Can I use Go (exes) with an existing Apache sever to serve dynamic content?
    For clarity, assume the scenario of a hosted website on a random host
    service, and no net/http package being used to start a Go http server.

    A tutorial maybe, a real world example, that would be nice.
    Thanks.

    --


    --
    André Moraes
    http://amoraes.info

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 9:43 am

    On Friday, November 2, 2012 3:37:09 PM UTC+2, André Moraes wrote:
    If you can configure your apache to use FCGI protocol, Go has a
    package in stdlib that can be used.

    Just check:

    http://golang.org/pkg/net/http/fcgi/

    It works almost the same way that net/http works but uses FCGI instead of
    HTTP.

    I know about CGI, FastCGI in Go.

    I'd like a simple setup and running info on shared-hosting, like what I can
    find for Python.
    One simple search on Google for "python shared-hosting apache" will get me
    more than I need for the task to be done.

    --
  • André Moraes at Nov 3, 2012 at 6:12 pm

    One simple search on Google for "python shared-hosting apache" will get me
    more than I need for the task to be done.
    Options for shared-hosting with Go:

    Google AppEngine -> you get the whole platform from Go, you have
    control over your own application and data, but network configuration
    and server configuration aren't available to you.
    (https://developers.google.com/appengine/?hl=pt-br)

    Heroku -> You can run Go and buy database space, you have more freedom
    than using Google App Engine. (http://www.heroku.com/)

    Virtual Private Server's (VPS)
    Linode -> have plans starting at 19,99 USD per month, very good
    hosting and you get DNS management for free. I never needed to use
    it's support, so I don't have nothing to say about that.
    (www.linode.com)

    Pgrmr -> They have plan's starting at 5 USD per month, but you are
    expected to understand what you are doing in your server. They give
    you the bare OS installation and a remote shell access. Paypal can be
    used. (http://prgmr.com/xen/)

    Others Shared-Hosting providers

    The alternative in this case is using CGI. The Apache configuration in
    this case, isn't Go specific, so just google for "apache shared
    hosting cgi". On the Go side, read
    (http://golang.org/pkg/net/http/cgi/).

    A rapid Google search gave this result:
    http://httpd.apache.org/docs/2.2/howto/cgi.html

    You will compile the Go program on your development machine, then
    upload the binary to your hosting provider. Keep in mind that you will
    need to know what OS and architecture (x86, amd64) the hosting
    provider is using.

    Hope this helps.

    --
    André Moraes
    http://amoraes.info

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 6:36 pm
    Thanks.

    The CGI part I got it working.

    I made this example:

    package main

    import (

         "os"

    )

    func main() {

         os.Stdout.WriteString("Content-Type: text/html;charset=utf-8\n\n")

         os.Stdout.WriteString("<h1>Hello, 世界</h1>")

    }


    compile it to hello.cgi,
    put it in the cgi-bin folder,
    followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
    and it works.

    How about fastCGI?

    --
  • Andy Balholm at Nov 3, 2012 at 7:19 pm

    On Saturday, November 3, 2012 11:36:30 AM UTC-7, Dumitru Ungureanu wrote:

    Thanks.

    The CGI part I got it working.

    I made this example:

    package main

    import (

    "os"

    )

    func main() {

    os.Stdout.WriteString("Content-Type: text/html;charset=utf-8\n\n")

    os.Stdout.WriteString("<h1>Hello, 世界</h1>")

    }


    compile it to hello.cgi,
    put it in the cgi-bin folder,
    followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
    and it works.

    How about fastCGI?
    There are packages in the standard library to support CGI and FastCGI:
    net/http/cgi and net/http/fcgi

    --
  • André Moraes at Nov 3, 2012 at 7:20 pm

    compile it to hello.cgi,
    put it in the cgi-bin folder,
    followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
    and it works.

    How about fastCGI?
    // http://golang.org/pkg/net/http/fcgi/
    package main

    import (
      "net"
      "net/http"
      "net/http/fcgi"
      "flag"
      "io"
      "log"
    )

    var (
      fcgiPort = flag.String("p", ":8081", "Port to listen for incoming
    FCGI requests")
    )

    // Just print the famous hello world
    func helloWord(w http.ResponseWriter, req *http.Request) {
      w.Header().Add("Content-Type", "text/html; charset=utf-8")
      io.WriteString(w, "<h1>Hello, 世界</h1>")
    }

    func main() {
             // http://golang.org/pkg/net/#Listen
      listener, err := net.Listen("tcp", *fcgiPort)
      if err != nil {
       // run to the hills
       log.Fatalf("Unable to start fcgi listener. Cause: %v", err)
      }

      // http://golang.org/pkg/net/http/#HandleFunc
      http.HandleFunc("/", helloWord)

             // http://golang.org/pkg/net/http/fcgi/#Serve
      err = fcgi.Serve(listener, http.DefaultServeMux)

      if err != nil {
       // an error, the FCGI can't handle client connections
       log.Fatalf("Error in the FCGI package. Cause: %v", err)
      }
    }

    Also, in your CGI example, you really should use
    http://golang.org/pkg/net/http/cgi/#Serve instead of writing directly
    into os.Stdout. This allow's you to use most of net/http package (and
    third-party libraries) even in a CGI application.

    --
    André Moraes
    http://amoraes.info

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 7:33 pm
    Thanks for the example.
    About the cgi/fastcgi packages:
    I was saying in the first post: "assume no net/http package being used". Is
    that possible?

    And what the Apache side setup would look like for this: httpd.conf,
    .htaccess directives?
    Thanks again.

    On Saturday, November 3, 2012 9:20:43 PM UTC+2, André Moraes wrote:

    compile it to hello.cgi,
    put it in the cgi-bin folder,
    followed the www.yoursite.com/cgi-bin/hello.cgi path in a browser
    and it works.

    How about fastCGI?
    // http://golang.org/pkg/net/http/fcgi/
    package main

    import (
    "net"
    "net/http"
    "net/http/fcgi"
    "flag"
    "io"
    "log"
    )

    var (
    fcgiPort = flag.String("p", ":8081", "Port to listen for incoming
    FCGI requests")
    )

    // Just print the famous hello world
    func helloWord(w http.ResponseWriter, req *http.Request) {
    w.Header().Add("Content-Type", "text/html; charset=utf-8")
    io.WriteString(w, "<h1>Hello, 世界</h1>")
    }

    func main() {
    // http://golang.org/pkg/net/#Listen
    listener, err := net.Listen("tcp", *fcgiPort)
    if err != nil {
    // run to the hills
    log.Fatalf("Unable to start fcgi listener. Cause: %v",
    err)
    }

    // http://golang.org/pkg/net/http/#HandleFunc
    http.HandleFunc("/", helloWord)

    // http://golang.org/pkg/net/http/fcgi/#Serve
    err = fcgi.Serve(listener, http.DefaultServeMux)

    if err != nil {
    // an error, the FCGI can't handle client connections
    log.Fatalf("Error in the FCGI package. Cause: %v", err)
    }
    }

    Also, in your CGI example, you really should use
    http://golang.org/pkg/net/http/cgi/#Serve instead of writing directly
    into os.Stdout. This allow's you to use most of net/http package (and
    third-party libraries) even in a CGI application.

    --
    André Moraes
    http://amoraes.info
    --
  • Dustin Sallings at Nov 3, 2012 at 7:46 pm
    Dumitru Ungureanu <itmitica@gmail.com>
    writes:
    Thanks for the example.
    About the cgi/fastcgi packages:
    I was saying in the first post: "assume no net/http package being
    used". Is that possible?
       Your code could do the same thing that code does, it's just harder.

       Do you have a particular reason for avoiding the well-tested standard
    library code in your deployment?

    --
    dustin

    --
  • Dumitru Ungureanu at Nov 3, 2012 at 7:53 pm
    Noe at all. At this point, the code has little importance. I chose it
    because it has fewer lines and because it's not the issue. It's how to
    deploy the code on an Apache sharing host environment. As fastCGI. Or
    anything else.
    On Saturday, November 3, 2012 9:47:07 PM UTC+2, Dustin wrote:

    Your code could do the same thing that code does, it's just harder.

    Do you have a particular reason for avoiding the well-tested standard
    library code in your deployment?

    --
    dustin
    --
  • Tamás Gulácsi at Nov 3, 2012 at 10:33 pm
    The main culprit is here: you ask how do you upload the code. But with go, you have to be able to upload the compiled binary!
    This is not what a very cheap web hosting provider allows...

    --
  • Youtube at Feb 15, 2016 at 4:42 am

    On Saturday, November 3, 2012 at 4:32:57 PM UTC-6, Tamás Gulácsi wrote:
    The main culprit is here: you ask how do you upload the code. But with go,
    you have to be able to upload the compiled binary!
    This is not what a very cheap web hosting provider allows...

    Incorrect. Many cheap hosting providers such as Hostgator allow 100
    percent native binary code. It's called CGI-BIN in your public html folder,
    and it has been around for decades. Infamous, and underused. Hostgator
    and thousands of other hosts allow these sorts of console mode CGI programs
    to run and have allowed them to run for decades.

    The cost of a cgi bin compatible linux host is about $5 to $12 per month.
    Cheaper if you prepay for a year or two. Now if only I could find a
    OpenBSD web host, or a freebsd webhost, since the market is flooded with
    Linux hosts which I've been using since year 2001 or earlier. BSD
    absolutely sucks when it comes to hosting marketshare, especially OpenBSD.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Peter Herth at Feb 15, 2016 at 10:38 am
    And if I might chime in with a small comment: what made CGI "inefficient"
    was often the fact that the cgi scripts have to be executed by their
    scripting engine. A (especially statically linked) executable as a cgi has
    little overhead to startup - even large executables can launch in 1 ms on a
    modern machine this way.

    Peter
    On Mon, Feb 15, 2016 at 5:42 AM, wrote:

    On Saturday, November 3, 2012 at 4:32:57 PM UTC-6, Tamás Gulácsi wrote:

    The main culprit is here: you ask how do you upload the code. But with
    go, you have to be able to upload the compiled binary!
    This is not what a very cheap web hosting provider allows...

    Incorrect. Many cheap hosting providers such as Hostgator allow 100
    percent native binary code. It's called CGI-BIN in your public html folder,
    and it has been around for decades. Infamous, and underused. Hostgator
    and thousands of other hosts allow these sorts of console mode CGI programs
    to run and have allowed them to run for decades.

    The cost of a cgi bin compatible linux host is about $5 to $12 per month.
    Cheaper if you prepay for a year or two. Now if only I could find a
    OpenBSD web host, or a freebsd webhost, since the market is flooded with
    Linux hosts which I've been using since year 2001 or earlier. BSD
    absolutely sucks when it comes to hosting marketshare, especially OpenBSD.

    --
    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+unsubscribe@googlegroups.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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dumitru Ungureanu at Nov 3, 2012 at 7:48 pm
    @Dustin

    I can't think of a way to make my self more clear than this:
    Has anyone implemented a real life example of a Go binary treated as
    fastCGI on Apache?

    The theory is all there, is the practice that' killing me.
    I know there are packages for cgi, fastcgi.
    I know Go binaries can run on many platforms.

    How exactly do I make use of an Apache sharing host environment (no nginx
    added) to serve dynamic content? The CGI part was never a problem. FastCGI.
    Something step-by-step would be nice.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 1, '12 at 6:52p
activeFeb 15, '16 at 10:38a
posts68
users16
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase