Adding configuration support for pic
This commit is contained in:
parent
05f4d8173d
commit
12b11a0fa1
3 changed files with 34 additions and 9 deletions
26
README.md
26
README.md
|
@ -5,6 +5,10 @@ that I took in Fall 2017 at UPT.
|
||||||
The scope of this project is to implement a simple server that handles multiple clients and allows the clients to
|
The scope of this project is to implement a simple server that handles multiple clients and allows the clients to
|
||||||
execute commands on it.
|
execute commands on it.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
//todo
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
The server can be configured via command line flags with the -ConfigPath option,
|
The server can be configured via command line flags with the -ConfigPath option,
|
||||||
|
@ -17,13 +21,25 @@ Sample Configuration File:
|
||||||
"address": "localhost",
|
"address": "localhost",
|
||||||
"port": "8080",
|
"port": "8080",
|
||||||
"maxDirDepth": 30,
|
"maxDirDepth": 30,
|
||||||
"absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars"
|
"absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars",
|
||||||
|
"pic": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The **config.json** file contains the following settings:
|
The **config.json** file contains the following settings:
|
||||||
|
|
||||||
Address - The address on which to serve
|
address - The address on which to serve
|
||||||
Port - The port
|
|
||||||
MaxDirDepth - The maximum depth the user can go into directories. A value of 30 means the user can cd into max 30 dirs.
|
port - The port
|
||||||
AbsoluteServePath - The path from where to serve the files.
|
|
||||||
|
maxDirDepth - The maximum depth the user can go into directories. A value of 30 means the user can cd into max 30 dirs.
|
||||||
|
|
||||||
|
absoluteServePath - The path from where to serve the files.
|
||||||
|
|
||||||
|
pic - The X and Y max size for the pic command. A value of 0 means original size
|
||||||
|
|
||||||
|
If one of the settings are changed, the server will reload the configuration.
|
||||||
|
Except for the absoluteServePath.
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
"github.com/zyxar/image2ascii/ascii"
|
"github.com/zyxar/image2ascii/ascii"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,8 +22,8 @@ func SendAsciiPic(c Client, path string) error {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
opt := ascii.Options{
|
opt := ascii.Options{
|
||||||
Width: 0,
|
Width: viper.GetInt("pic.x"),
|
||||||
Height: 0,
|
Height: viper.GetInt("pic.y"),
|
||||||
Color: false,
|
Color: false,
|
||||||
Invert: false,
|
Invert: false,
|
||||||
Flipx: false,
|
Flipx: false,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,6 +32,8 @@ func setDefaultConfiguration() {
|
||||||
viper.SetDefault("configPath", ConfigPath)
|
viper.SetDefault("configPath", ConfigPath)
|
||||||
viper.SetDefault("maxDirDepth", 30)
|
viper.SetDefault("maxDirDepth", 30)
|
||||||
viper.SetDefault("absoluteServePath", "./")
|
viper.SetDefault("absoluteServePath", "./")
|
||||||
|
viper.SetDefault("pic.x", 0)
|
||||||
|
viper.SetDefault("pic.y", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializedConfiguration initializes the configuration for the application.
|
// InitializedConfiguration initializes the configuration for the application.
|
||||||
|
@ -39,7 +42,12 @@ func InitializedConfiguration() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
setDefaultConfiguration()
|
setDefaultConfiguration()
|
||||||
|
|
||||||
loadConfigFromFile()
|
loadConfigFromFile()
|
||||||
BasePath = viper.GetString("AbsoluteServePath")
|
|
||||||
|
viper.WatchConfig()
|
||||||
|
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||||
|
log.Println("Reloaded configuration file successfully!")
|
||||||
|
})
|
||||||
|
|
||||||
|
BasePath = viper.GetString("absoluteServePath")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue