Skip to content

Commit

Permalink
feat: added a simple hello world service for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Oct 28, 2021
1 parent 12c9ef5 commit 25b185a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/vproxy/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ func parseFlags() {
},
},
},
{
Name: "hello",
Usage: "Start a simple Hello World http service",
Action: startHello,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
Value: "127.0.0.1",
Usage: "Host or IP to bind on",
},
&cli.IntFlag{
Name: "port",
Value: 8888,
Usage: "Port to listen on",
},
},
},
{
Name: "version",
Usage: "print the version",
Expand Down
4 changes: 4 additions & 0 deletions bin/vproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func uninstallCAROOT() error {
return nil
}

func startHello(c *cli.Context) error {
return vproxy.StartHello(c.String("host"), c.Int("port"))
}

func main() {
parseFlags()
}
20 changes: 20 additions & 0 deletions hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package vproxy

import (
"fmt"
"net/http"
)

// StartHello world service on the given host/port
//
// This is a simple service which always responds with 'Hello World'.
// It's mainly here to serve as a simple demo of vproxy's abilities (see readme).
func StartHello(host string, port int) error {
fmt.Printf("~> starting vproxy hello service at http://%s:%d\n", host, port)
return http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), http.HandlerFunc(helloHandler))
}

func helloHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprintf(w, "<h1>Hello World!</h1>")
}

0 comments on commit 25b185a

Please sign in to comment.