feat: add basic http server with hello world
This commit is contained in:
parent
4f19235d8e
commit
35ca4d49cc
1 changed files with 28 additions and 0 deletions
28
cmd/dropr-server/main.go
Normal file
28
cmd/dropr-server/main.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const PORT = ":8080"
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
|
||||
_, err := fmt.Fprintf(w, "Hello, World!")
|
||||
if err != nil {
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
fmt.Println("Listening on port " + PORT)
|
||||
err := http.ListenAndServe(PORT, nil)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue