-
-
Save parzibyte/2862172f4959cfe9622285d70513f39f 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
package main | |
import ( | |
"fmt" | |
"github.com/gorilla/mux" | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
// Crear el enrutador y definir las rutas en la función definirRutas | |
enrutador := mux.NewRouter() | |
// aquí definir todas las rutas... | |
//enrutador.HandleFunc... | |
// Dirección del servidor. En este caso solo indicamos el puerto | |
// pero podría ser algo como "127.0.0.1:8000" | |
direccion := ":8000" | |
servidor := &http.Server{ | |
Handler: enrutador, | |
Addr: direccion, | |
// Timeouts para evitar que el servidor se quede "colgado" por siempre | |
WriteTimeout: 15 * time.Second, | |
ReadTimeout: 15 * time.Second, | |
} | |
fmt.Printf("Escuchando en %s. Presiona CTRL + C para salir", direccion) | |
log.Fatal(servidor.ListenAndServe()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment