Skip to content

Instantly share code, notes, and snippets.

@nxpatterns
Forked from filewalkwithme/main.go
Created May 21, 2021 20:38
Show Gist options
  • Save nxpatterns/52f7f133a4080f31a645e778c75f4b44 to your computer and use it in GitHub Desktop.
Save nxpatterns/52f7f133a4080f31a645e778c75f4b44 to your computer and use it in GitHub Desktop.

Revisions

  1. @filewalkwithme filewalkwithme renamed this gist Feb 8, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @filewalkwithme filewalkwithme created this gist Feb 8, 2015.
    28 changes: 28 additions & 0 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    package main

    import (
    "net/http"
    )

    func main() {
    go func() {
    http.ListenAndServe(":8001", &fooHandler{})
    }()

    //the last call is outside goroutine to avoid that program just exit
    http.ListenAndServe(":8002", &barHandler{})
    }

    type fooHandler struct {
    }

    func (m *fooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Listening on 8001: foo "))
    }

    type barHandler struct {
    }

    func (m *barHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Listening on 8002: bar "))
    }