Advertisement
Guest User

http-server

a guest
Nov 23rd, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.49 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "net/http"
  5.     "strings"
  6. )
  7.  
  8. func sayHello(w http.ResponseWriter, r *http.Request) {
  9.     name := "World"
  10.     url := strings.Trim(r.RequestURI, "/")
  11.     if len(url) > 0 {
  12.         name = strings.Split(url, "/")[0]
  13.         name = strings.ToUpper(name[0:1]) + name[1:] // change first symbol to Uppercase
  14.     }
  15.     w.Write([]byte("Hello, " + name + "!"))
  16. }
  17.  
  18. func main() {
  19.     http.HandleFunc("/", sayHello)
  20.     err := http.ListenAndServe(":80", nil)
  21.     if err != nil {
  22.         panic(err.Error())
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement