-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into minor-fixes
- Loading branch information
Showing
24 changed files
with
450 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package main | |
import ( | ||
"flag" | ||
"fmt" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/GenerateNU/sac/backend/src/config" | ||
|
@@ -11,13 +13,21 @@ import ( | |
"github.com/GenerateNU/sac/backend/src/server" | ||
) | ||
|
||
// @title SAC API | ||
// @version 1.0 | ||
// @description Backend Server for SAC App | ||
// @contact.name David Oduneye and Garrett Ladley | ||
// @contact.email [email protected] | ||
// @host 127.0.0.1:8080 | ||
// @BasePath /api/v1 | ||
func CheckServerRunning(host string, port uint16) error { | ||
address := fmt.Sprintf("%s:%d", host, port) | ||
conn, err := net.Dial("tcp", address) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
return nil | ||
} | ||
|
||
func Exit(format string, a ...interface{}) { | ||
fmt.Fprintf(os.Stderr, format, a...) | ||
os.Exit(0) | ||
} | ||
|
||
func main() { | ||
onlyMigrate := flag.Bool("only-migrate", false, "Specify if you want to only perform the database migration") | ||
configPath := flag.String("config", filepath.Join("..", "..", "config"), "Specify the path to the config directory") | ||
|
@@ -27,12 +37,17 @@ func main() { | |
|
||
config, err := config.GetConfiguration(*configPath, *useDevDotEnv) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error getting configuration: %s", err.Error())) | ||
Exit("Error getting configuration: %s", err.Error()) | ||
} | ||
|
||
err = CheckServerRunning(config.Application.Host, config.Application.Port) | ||
if err == nil { | ||
Exit("A server is already running on %s:%d.\n", config.Application.Host, config.Application.Port) | ||
} | ||
|
||
db, err := database.ConfigureDB(*config) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error configuring database: %s", err.Error())) | ||
Exit("Error migrating database: %s", err.Error()) | ||
} | ||
|
||
if *onlyMigrate { | ||
|
@@ -41,13 +56,13 @@ func main() { | |
|
||
err = database.ConnPooling(db) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error connecting to database: %s", err.Error())) | ||
Exit("Error with connection pooling: %s", err.Error()) | ||
} | ||
|
||
app := server.Init(db, *config) | ||
|
||
err = app.Listen(fmt.Sprintf("%s:%d", config.Application.Host, config.Application.Port)) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error starting server: %s", err.Error())) | ||
Exit("Error starting server: %s", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
_ "github.com/lib/pq" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func BackendCommand() *cli.Command { | ||
command := &cli.Command{ | ||
Name: "backend", | ||
Usage: "Starts the backend server", | ||
Aliases: []string{"be"}, | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "use-dev-dot-env", | ||
Usage: "Use the .env file in the backend directory", | ||
Aliases: []string{"d"}, | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
err := RunBackend() | ||
if err != nil { | ||
return cli.Exit(err.Error(), 1) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return command | ||
} | ||
|
||
func RunBackend() error { | ||
cmd := exec.Command("go", "run", "main.go") | ||
cmd.Dir = BACKEND_DIR | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err := cmd.Run() | ||
if err != nil { | ||
return fmt.Errorf("error starting backend: %w", err) | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.