Is there a way to run web applications based on Go Lang ?

  • sean replied to this.

    anjanesh yep!

    1. Create a new proxy port app at https://my.opalstack.com/apps/ and make a note of its port assignment.
    2. Assign the app to a site at https://my.opalstack.com/domains/.
    3. Configure your golang app to use your assigned port and run it.

    The specific steps required for the third step will vary depending on the specific app, eg some apps might use a config file, others might take a commandline parameter, etc.

    Thank you for your response Sean - I'll circle back to this when I reach to the point of deployment of the app which I am trying out on localhost.

    I uploaded my sample go project contents to the proxy port app (app name go) onto the server.
    But I can't seem to run the go command.

    [username@opalX go]$ go run cmd/web/*.go
    fork/exec /tmp/go-build316634104/b001/exe/main: permission denied
    • sean replied to this.

      anjanesh you can't execute things from /tmp so try running these commands first:

      mkdir -p ~/tmp
      export TMPDIR=$HOME/tmp

      This should let your app know that it should create its tmp files in your own home directory where the noexec restriction does not exist.

      This is just amazing - I finally got a basic 2-page go app up (using Go's in-built HTML templating system) and running on OpalStack. This is one month after my first Python / Django project started on OpalStack too. This is totally off from my regular PHP based apps that I've been working on for the last 18 years. It has taken that much time to deviate from the PHP world.

      In case anyone wants to try out web apps in Go, do check out https://www.udemy.com/user/trevor-sawler/ - this is the first course where I've come across building web apps using Go.

        anjanesh Nice!

        This is one of the benefits of the flexible hosting environment that we provide. The "Proxy Port" application type gives you the ability to serve up nearly any web application that can serve HTTP on a network port.

        This means you're always able to try something new - for example, if some new web app or framework were released today, you're able to install it and run it today without waiting for Opalstack to create an official installer for it or whatever.

        How many other managed shared hosting providers will let you do that? 🙂

        What happens when we do go get -u github.com/justinas/nosurf ? Where does the 3rd party package(s) get loaded into ?

        • sean replied to this.

          anjanesh If you have a GOPATH environment variable set then go get will install packages to that location, otherwise it installs to $HOME/go.

          I like the fact that in Go we can just add a github repo directly as a module without the need for creating directories explicitly. github.com/justinas/nosurf doesn't have a single folder - all just .go files and gets imported as Go modules directly.

          a year later

          Hi Sean,

          I was able to follow the instructions above to run a GoToSocial instance successfully but I was wondering how I could register the executable as a service.

          Thanks !

          • nick replied to this.

            bchhun

            Since we do not offer root access, setting up a service wont be doable. Though a simple way to keep it active would be to use something like nohup/daemonize when launching the instance. Or use a cron task to schedule the app or your own start script.

            Some examples on the forum:
            https://community.opalstack.com/d/1031-how-do-i-create-a-cron-job
            https://community.opalstack.com/d/95-restart-jobs

              thank you Nick !

              I'll try this out this evening.

              Have a good friday !

              6 days later
              Mastodon