Created
July 29, 2019 22:17
-
-
Save parzibyte/d10701804a0d19a009aafbe45a14cbcd to your computer and use it in GitHub Desktop.
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
/* | |
Ejemplo 2: otras rutas en servidor HTTP con Go | |
@author parzibyte | |
*/ | |
package main | |
import ( | |
"fmt"// Imprimir en consola | |
"io"// Ayuda a escribir en la respuesta | |
"log"//Loguear si algo sale mal | |
"net/http"// El paquete HTTP | |
) | |
func main() { | |
http.HandleFunc("/hola", func(w http.ResponseWriter, peticion *http.Request) { | |
io.WriteString(w, "Solicitaste hola") | |
}) | |
http.HandleFunc("/ruta/un/poco/larga", func(w http.ResponseWriter, peticion *http.Request) { | |
io.WriteString(w, "Solicitaste ruta/un/poco/larga") | |
}) | |
direccion := ":8080" // Como cadena, no como entero; porque representa una dirección | |
fmt.Println("Servidor listo escuchando en " + direccion) | |
log.Fatal(http.ListenAndServe(direccion, nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment