Compare commits

...

2 commits

Author SHA1 Message Date
Logan Gatlin 47a3550430
Fixed README 2024-10-11 05:39:44 -05:00
Logan ef375752dc Made IP and port configurable 2024-10-11 05:38:15 -05:00
2 changed files with 12 additions and 6 deletions

View file

@ -7,6 +7,9 @@ within a restricted amount of time to make art.
2. Run the command `go run .` inside this folder
3. View the website at [127.0.0.1:8080](http://127.0.0.1:8080/)
You can choose a different IP address or port using the flags:
`go run . -ip=192.168.0.1 -port=3000`
## Go project structure
* [go.mod](go.mod) Go version and library dependencies
* [go.sum](go.sum) Checksums for libraries
@ -24,4 +27,4 @@ CSS framework.
* [Registration page](static/register.html)
yaya
testing
testing

View file

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"net/http"
@ -8,9 +9,6 @@ import (
"github.com/gorilla/sessions"
)
const ADDRESS = "127.0.0.1"
const PORT = "8080"
type Server struct {
// Registered user information
Users map[string]UserData
@ -19,6 +17,11 @@ type Server struct {
}
func main() {
ipFlag := flag.String("ip", "127.0.0.1", "IP address to receive traffic from")
portFlag := flag.String("port", "8080", "Port to receive traffic from")
flag.Parse()
address := *ipFlag
port := *portFlag
// Create server object
secret := []byte("super-secret-key")
server := Server{
@ -40,8 +43,8 @@ func main() {
})
http.HandleFunc("/secret", server.secret)
// Start web server at 127.0.0.1:8080
fmt.Printf("Listening to %s on port %s...\n", ADDRESS, PORT)
err := http.ListenAndServe(ADDRESS+":"+PORT, nil)
fmt.Printf("Listening to %s on port %s...\n", address, port)
err := http.ListenAndServe(address+":"+port, nil)
// Print any errors
if err != nil {
fmt.Println("Error starting server:")