Skip to content

Simple tutorial showing how to host a simple Golang web app using Railway.app

Notifications You must be signed in to change notification settings

chandler767/Golang-on-Railway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

How to deploy a Golang app on Railway

This is a simple tutorial showing how to host a basic Golang web app using Railway. Follow this tutorial to learn how to:

  • Create a new project in Railway.
  • Deploy a golang 'hello world' web app from GitHub to Railway.
  • Configure variables for your app.
  • Generate a domain for your app.
  • Next steps with Railway.

What is Railway?

Railway.app is a Platform as a Service (PaaS), presenting a comprehensive environment for constructing and deploying applications.

With Railway App, the heavy lifting is taken care of, requiring only your code input. This cutting-edge technology breaks free from project constraints as its cloud backend accommodates both modest and extensive operations. Recognizing the unique demands of each project, Railway equips you with technologies that extend your application's capabilities through customizable extensions.

Why use Railway to deploy a Golang App?

  • Simplified Deployment Process: Railway App streamlines the deployment process for your Golang application. With Railway App, you only need to provide your code, and the platform takes care of the intricate deployment steps, such as setting up servers, managing dependencies, and configuring environments. This means you can focus more on coding and less on deployment complexities.
  • Versatile Technology: Railway App's innovative technology is versatile and adaptable to a wide range of project types. Whether you're working on a small personal project or a large-scale business application, Railway App's cloud backend is equipped to handle the demands of both scenarios, ensuring your application runs smoothly regardless of its scale.
  • Seamless Transition from Existing Repositories: One of Railway App's strengths is its ability to seamlessly integrate with your existing repositories. You can continue working on projects that are already in progress without needing to make significant changes to your development workflow. This convenience can save time and effort during the transition to the new platform.
  • Reduced Maintenance Overhead: Railway App's managed environment reduces the burden of maintenance and operational tasks. You can rely on the platform to handle updates, scaling, and security measures, freeing you from routine maintenance duties and allowing you to focus on enhancing your application.

Deploying Go to Railway

  1. Fork this repo to your GitHub account. You'll link your cloned repo to your Railway account. Take a look at main.go to see your basic web application (There is only one file for the whole project). Notice that the server will listen on 0.0.0.0 and the port is set by the "PORT" environment variable generated by Railway.
http.ListenAndServe("0.0.0.0:"+os.Getenv("PORT"), nil)
  1. Later, when we configure the app in Railway, we'll configure the "NAME" environment variable ourselves.
	fmt.Fprintf(w, "Hello, %s!", os.Getenv("NAME"))
  1. Go to https://railway.app and click "Start a New Project".
  2. Click "Deploy from a GitHub repo".
  3. (If needed) Login with GitHub and grant access to view your repos. Click "Deploy from a GitHub repo" again after signing in.

6. Select the repo you just forked. "Golang-on-Railway"

7. Click "Add variables". Add a variable with the VARIABLE_NAME value set to "NAME". Set VALUE of the "NAME" variable to be "WORLD" or set it to your name. This will later be used to display your name when you make a request to the application. See main.go for more info.

8. Go to the "Settings" tab. Scroll down to "Domains" and click "Generate Domain". This is also where you can configure a custom domain later.

9. Click on the generated domain. You should see your Go app running.

Next Steps with Railway and Golang