Object-Storage-Railway
- Created by Ramzi Al-Aruri
- This application a high level incopration of Object storage using Railway and Google Cloud Storage.
- Current App Structure
/Object-Storage-Railway
│
├── buckets // Database other configuration
| ├── bucket_operator.go // Bucket Operations (Write, Read)
│ └── create_bucket.go // Creating the Bucket, Connection and decoding
|
|── handlers // Logic for API (Eventually will include router)
| └── health.go // Health Check on API
|
|── utils // constants and tools (i.e.) dotenv
| └── dotenv.go // setting up the .env extract
|
|── object_creator // Mocking Json file creator
| └── cheese_creator.go // Mock json creation & deletion
|
|── .env_example // Example .env
|── go.mod // configuration setup by Go
|── go.sum // configuration setup by Go
|── *main.go* *// Entry point for app *
└── README.md // This Readme!
- This is how I manage my local Go & Python installations
- You can have a seperate instance of Go versions for each project.
- Installing asdf using homebrew
brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zsh_profile
- Installing go
asdf plugin add go
asdf install go latest
- Setting a Version
asdf global go latest
if you need to a set a local env.asdf local go latest
-
Create a Directory i.e.
hello
-
Go into the dircectory
cd hello
-
get the path of the directory
pwd
>> documents/projects/hello
OR just name it based on the directory i.e. object-storage.app
-
init the project
go mod init object-storage.app
-
check the go.mod file
cat go.mod
-
run
go install
-
create a main.go file
add this code snippet
package main
import "fmt"
func main() {
fmt.Println("Hello, SlimeCorp")
}
- finally run the file
go run main.go
- Never commit your json service account details from GCP.
- This is just one method to get service accounts to work in Railway for GCP specfically
- In your terminal run
cat object-storage-railway.json | base64
output will be a encoded base64 string copy and use that and .ENV variable or value inside of Railway.
- Inside the code we have a function that will decode the string at runtime to use the service account permissions.
func CovertStringToJSON(env_details string) []byte {
decoded_json, err := base64.StdEncoding.DecodeString(env_details)
if err != nil {
panic(err)
}
return decoded_json
}
- Fiber: https://gofiber.io/
- Google Cloud: https://cloud.google.com
- Railway: railway.app
- Link Git Repo to Railway
- Add encoded base64 service account value to the variable of the railway project for this repo.
- Add ENV=PROD in addition to the variables. This allows you to use a .env file locally if you want to test before you deploy to Railway but the beauty of Railway it can be part of your testing & ci/cd stack.