From 85416def641549d656a77270a220a349aeb7abb4 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Sun, 18 Aug 2024 00:34:52 +0300 Subject: [PATCH] Update functions.go --- interpreter/functions.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/interpreter/functions.go b/interpreter/functions.go index 72e9464..ae697e3 100644 --- a/interpreter/functions.go +++ b/interpreter/functions.go @@ -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)) }