Skip to content

Instantly share code, notes, and snippets.

@juliocabrera820
Created April 5, 2020 00:33
Show Gist options
  • Save juliocabrera820/e21fdfdc49bc8a661414486bc9210065 to your computer and use it in GitHub Desktop.
Save juliocabrera820/e21fdfdc49bc8a661414486bc9210065 to your computer and use it in GitHub Desktop.
Método HandleFunc
package main
import (
"net/http"
"log"
"fmt"
)
func main() {
http.HandleFunc("/", func (w http.ResponseWriter,r *http.Request){
fmt.Fprintf(w,"Hola")
})
log.Fatal(http.ListenAndServe(":3000",nil))
}
  • Usar el método HandleFunc de http
  • Se pasan 2 parámetros
  • El primero es la URI, el segundo es una función anónima
  • Dentro de la función anónima se pasas 2 parámetros w *http.ResponseWriter, r *http.Request
  • con w le respondemos al cliente en el navegador
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment