Skip to content

Commit

Permalink
Update functions.go
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 17, 2024
1 parent 6b618b0 commit 85416de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions interpreter/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,18 @@ func httpListenFunction(interp *interpreter, pos Position, args []Value) Value {
panic(typeError(pos, "httpRegisterFunction() requires 1 arg, got %d", len(args)))
}

fmt.Println("Server is running on port http://localhost:8080")
portOrAddress, ok := args[0].(string)
if !ok {
panic(typeError(pos, "httpListenFunction() requires first argument to be a string"))
}

if !strings.Contains(portOrAddress, ":") {
fmt.Printf("Server is starting on %s...\n", portOrAddress)
} else {
fmt.Printf("Server is starting on http://localhost%s...\n", portOrAddress)
}

err := http.ListenAndServe(":8080", nil)
err := http.ListenAndServe(portOrAddress, nil)
if err != nil {
panic(runtimeError(pos, "httpListen() error: %v", err))
}
Expand Down

0 comments on commit 85416de

Please sign in to comment.