Last active
March 19, 2021 08:29
-
-
Save iamjjanga-ouo/c055c66dacf3a159639c411f4d7f32ce to your computer and use it in GitHub Desktop.
GoWeb: basic: net/http ListenAndServe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ListenAndServe(addr string, handler Handler) error | |
// | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type MyWebserverType bool | |
// Handler interface는 ServeHTTP 메서드를 가지고있다. | |
// 따로 custom func와 메서드를 구현해서 Handler를 사용할 수 있다. | |
func (m MyWebserverType) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintln(w, "well, hello there !!!") | |
fmt.Fprintf(w, "Request is \n%+v", r) | |
} | |
func main() { | |
var k MyWebserverType | |
http.ListenAndServe("localhost:8080", k) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment