diff --git a/README.md b/README.md index 6b7ef1f..7d2cceb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Le fichier de configuration est passé dans `Configure()` et doit être au forma "TemplateIncludePath": "templates/", "TemplateLayoutPath": "templates/layouts/", "TemplateExtensionPattern": "*.gohtml", - "ServerPort": ":8000", + "ServerPort": "8000", + "ServerListenAdress": "0.0.0.0", "Domain": "http://git.an", "MainTemplate": "{{define \"main\" }} {{ template \"base\" . }} {{ end }}", "Debug": false, @@ -22,6 +23,8 @@ Le fichier de configuration est passé dans `Configure()` et doit être au forma Des paramètres par défaut sont utilisé dans tous les cas. +Changer ServerListenAdress permet de contrôler sur quelles adresses écoutent le serveur. Par exemple localhost n'écoute que sur la machine hôte tandis que 0.0.0.0 écoute toutes les connexions entrantes. + Le système de session utilise un dossier `.session` généré automatiquement, attention aux permissions ! Il est possible de rajouter ses propres backend pour le système de session en les enregistrant grâce à la fonction `SessionProviderRegister`. Les backends doivent respecter l'interface `SessionProvider`. diff --git a/gowebframework.go b/gowebframework.go index 680c285..51a47c3 100644 --- a/gowebframework.go +++ b/gowebframework.go @@ -2,7 +2,7 @@ * @Author: Bartuccio Antoine * @Date: 2018-07-14 11:32:11 * @Last Modified by: klmp200 -* @Last Modified time: 2018-07-17 23:55:22 +* @Last Modified time: 2018-07-18 19:41:18 */ package gowebframework @@ -29,6 +29,7 @@ type Config struct { StaticFolderPath string TemplateExtensionPattern string ServerPort string + ServerListenAdress string SessionProvider string Domain string Debug bool @@ -54,8 +55,8 @@ func Configure(config_file_name string, custom_config_file_name string) { // Starts server func Start() { http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(ServerConfig.StaticFolderPath)))) - log.Println("Server listening on http://localhost" + ServerConfig.ServerPort) - log.Fatal(http.ListenAndServe(ServerConfig.ServerPort, nil)) + log.Println("Server listening on http://" + ServerConfig.ServerListenAdress + ":" + ServerConfig.ServerPort) + log.Fatal(http.ListenAndServe(ServerConfig.ServerListenAdress+":"+ServerConfig.ServerPort, nil)) } func loadDefaultConfiguration() { @@ -63,7 +64,8 @@ func loadDefaultConfiguration() { ServerConfig.TemplateIncludePath = "templates/" ServerConfig.TemplateLayoutPath = "templates/layouts/" ServerConfig.TemplateExtensionPattern = "*.gohtml" - ServerConfig.ServerPort = ":8000" + ServerConfig.ServerPort = "8000" + ServerConfig.ServerListenAdress = "0.0.0.0" ServerConfig.Domain = "localhost" ServerConfig.MainTemplate = `{{define "main" }} {{ template "base" . }} {{ end }}` ServerConfig.Debug = false