Add possibility to listen only on specified addreses
the build was successful Details

This commit is contained in:
Antoine Bartuccio 2018-07-18 19:49:57 +02:00
parent 751f8a7a89
commit e06a19c776
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 10 additions and 5 deletions

View File

@ -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`.

View File

@ -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