To start developing a Go project the go mod init command needs to be run with a domain of choice. This project is using github.com/lucas-kern/whir_server as the GitHub repository so has been initialized with that domain.
In order to import a package into another package for use it will need to be in the format of
import github.com/lucas-kern/whir_server/{PATH}/{TO}{FILE}
With the {PATH}/{TO}{FILE} being the directory structure of the imported package.
To add other packages from GitHub that are not in this repository use go get {PACKAGE-DOMAIN}
If needed can run go mod tidy to update current packages and remove unused ones.
Read How to Write Go Code for a simple understanding of how to organize the code
EXPORT ENV VARIABLES FIRST
To start the project run go run app/main.go
Stop the server by hitting ctrl + c
We will be using MongoDB community Server for development and mongodb cloud for group development.
test_db URL: mongodb+srv://devtesting1:devtesting1@cluster0.j4x0atl.mongodb.net/?retryWrites=true&w=majority
- Need to create index on field:
locationof type:2dspherein order to use GeoSpatial
- Install homebrew if you don't already have it.
- Then follow the MongoDB homebrew install instructions
- Install the Community version 6.0
- EXPORT ENV VARIABLES FIRST
- using a terminal
mongod --config /usr/local/etc/mongod.conf- NOTE: Will use the terminal window to print logs
- Run as a service
brew services start mongodb-community@6.0
- Run
mongoshin a different terminal to connect to the running instance- Opens up the Mongo shell
- Type .exit, exit, or exit().
- Type quit or quit().
- Press Ctrl + D.
- Press Ctrl + C twice.
- hit
ctrl + con the service and the shell if ran in the shell - run
brew services stop mongodb-community@6.0to stop the backgroun service
- Donwload the MSI file for the community server version 6.0 from MongoDB
- Follow the Installer to get it installed
- NOTE: Select
completeversion to ensure everything you need is installed. - Should install as a service - For more detailed instructions follow the MongoDB instructions
- After installing the MongoDB Server install the mongosh shell by following the Mongosh Install Instructions
- Run
mongoshfrom any terminal to connect to the default port of 27017 - This is equivalent to runningmongosh "mongodb://localhost:27017"
To disconnect from a deployment and exit mongosh, you can:
- Type .exit, exit, or exit().
- Type quit or quit().
- Press Ctrl + D.
- Press Ctrl + C twice.
- Open the Windows Services Manager on your Windows 11 or Windows 10 computer, do the following:
- Right-click on the Start button to open the WinX Menu
- Select Run
- Type services.msc in the Run box which opens
- Windows Services Manager will open.
- Find the MongoDB Service in the console and
right click - Select
Stop
- run
go run scripts/seed-database - in mongo, run
show dbs - check for the 'whir' instance
- Tests go in the
testsdirectory - Follow the direcotry structure of the file you are testing and add
_test.goto the name of the file
- ex) If you are testing
app/model/basethen the test directory should betests/model/base_test
- To run the tests run
go test ./tests/*
- Could run a specific test file by giving the direct path to test
- Set the Linux env variables * GOOS=linux GOARCH=amd64
- Name the build with the release version number * GOOS=linux GOARCH=amd64 go build -o whir-server-1.0
GOOS=linux GOARCH=amd64 go build -o whir-server-{VERSION} ./app
scp -i {PATH TO PRIVATE KEY} {PATH TO SERVER BINARY} {PATH TO AWS INSTANCE}- example:
scp -i ~/Downloads/whirInstance.pem /Users/lucaskern/Desktop/whir-server/whir-server-1.0 ec2-user@ec2-3-137-173-110.us-east-2.compute.amazonaws.com:/home/ec2-user/server
- example:
- SSH into machine
-
ssh -i {PATH TO PRIVATE KEY} ec2-user@ec2-3-137-173-110.us-east-2.compute.amazonaws.com - Set ENV variables from the .env file
- Run the server in the background of the instance
-
nohup ./whir-server-1.0 &