summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--README.md9
-rw-r--r--binnit.cfg2
-rw-r--r--config.go8
-rw-r--r--main.go6
5 files changed, 22 insertions, 10 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..18f72b0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+GO=go
+
+all: binnit
+
+binnit: main.go templ.go config.go
+ $(GO) build -o binnit main.go templ.go config.go
+
diff --git a/README.md b/README.md
index 8a61d89..f81c22f 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## binit -- minimal pastebin-like in golang
+## binnit -- minimal pastebin-like in golang
That's just it. Preliminary version of a minimal, no-fuss
pastebin-like service in golang.
@@ -12,8 +12,9 @@ equal to the paste ID. The unique ID of a paste is obtained from the
SHA256 of the concatenation of title, time, and content. Rendering is
minimal, but can be enhanced.
-`binit` is currently configured through a simple key=value
-configuration file. The available options are:
+`binnit` is currently configured through a simple key=value
+configuration file, whose name can be specified on the command line
+through the option `-c <config\_file>`. The available options are:
* server\_name (the FQDN where the service is reachable from outside)
* bind\_addr (the address to listen on)
@@ -22,6 +23,8 @@ configuration file. The available options are:
* templ\_dir (the folder where HTML files and templates are kept)
* max_size (the maximum allowed length of a paste, in bytes. Larger
pastes will be trimmed to that length)
+* log_fname (path to the logfile)
+
### TODO
diff --git a/binnit.cfg b/binnit.cfg
index a1709c2..e404f8a 100644
--- a/binnit.cfg
+++ b/binnit.cfg
@@ -20,3 +20,5 @@ templ_dir=./html
## max size of a paste, in bytes (cannot exceed 65535)
max_size=16384
+## logfile
+log_file="./binnit.log" \ No newline at end of file
diff --git a/config.go b/config.go
index 7313356..9967ab8 100644
--- a/config.go
+++ b/config.go
@@ -41,8 +41,8 @@ type Config struct {
bind_port string
paste_dir string
templ_dir string
- log_fname string
max_size uint16
+ log_file string
}
@@ -54,8 +54,8 @@ func (c Config) String() string {
s+= "Listening on: " + c.bind_addr + ":" + c.bind_port +"\n"
s+= "paste_dir: " + c.paste_dir + "\n"
s+= "templ_dir: " + c.templ_dir + "\n"
- s+= "log_fname: " + c.log_fname + "\n"
s+= "max_size: " + string(c.max_size) + "\n"
+ s+= "log_file: " + c.log_file + "\n"
return s
@@ -93,8 +93,8 @@ func parse_config (fname string, c *Config) error {
c.paste_dir = strings.Trim(fields[1], " \t\"")
case "templ_dir":
c.templ_dir = strings.Trim(fields[1], " \t\"")
- case "log_fname":
- c.log_fname = strings.Trim(fields[1], " \t\"")
+ case "log_file":
+ c.log_file = strings.Trim(fields[1], " \t\"")
case "max_size":
if m_size, err := strconv.ParseUint(fields[1], 10, 16); err == nil {
c.max_size = uint16(m_size)
diff --git a/main.go b/main.go
index f241701..4aef702 100644
--- a/main.go
+++ b/main.go
@@ -43,8 +43,8 @@ var p_conf = Config{
bind_port: "8000",
paste_dir: "./pastes",
templ_dir: "./tmpl",
- log_fname: "./binnit.log",
max_size: 4096,
+ log_file: "./binnit.log",
}
@@ -171,9 +171,9 @@ func main() {
parse_config("binnit.cfg", &p_conf)
- f, err := os.OpenFile(p_conf.log_fname, os.O_APPEND | os.O_CREATE | os.O_RDWR, 0600)
+ f, err := os.OpenFile(p_conf.log_file, os.O_APPEND | os.O_CREATE | os.O_RDWR, 0600)
if err != nil {
- fmt.Fprintf(os.Stderr, "Error opening logfile: %s. Exiting\n", p_conf.log_fname)
+ fmt.Fprintf(os.Stderr, "Error opening log_file: %s. Exiting\n", p_conf.log_file)
os.Exit(1)
}
defer f.Close()