Added a Makefile and log_file option to the config file

master 0.1
KatolaZ 8 years ago
parent 4a9c3b4604
commit dece484ef7
  1. 7
      Makefile
  2. 9
      README.md
  3. 2
      binnit.cfg
  4. 8
      config.go
  5. 6
      main.go

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

@ -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 That's just it. Preliminary version of a minimal, no-fuss
pastebin-like service in golang. 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 SHA256 of the concatenation of title, time, and content. Rendering is
minimal, but can be enhanced. minimal, but can be enhanced.
`binit` is currently configured through a simple key=value `binnit` is currently configured through a simple key=value
configuration file. The available options are: 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) * server\_name (the FQDN where the service is reachable from outside)
* bind\_addr (the address to listen on) * 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) * templ\_dir (the folder where HTML files and templates are kept)
* max_size (the maximum allowed length of a paste, in bytes. Larger * max_size (the maximum allowed length of a paste, in bytes. Larger
pastes will be trimmed to that length) pastes will be trimmed to that length)
* log_fname (path to the logfile)
### TODO ### TODO

@ -20,3 +20,5 @@ templ_dir=./html
## max size of a paste, in bytes (cannot exceed 65535) ## max size of a paste, in bytes (cannot exceed 65535)
max_size=16384 max_size=16384
## logfile
log_file="./binnit.log"

@ -41,8 +41,8 @@ type Config struct {
bind_port string bind_port string
paste_dir string paste_dir string
templ_dir string templ_dir string
log_fname string
max_size uint16 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+= "Listening on: " + c.bind_addr + ":" + c.bind_port +"\n"
s+= "paste_dir: " + c.paste_dir + "\n" s+= "paste_dir: " + c.paste_dir + "\n"
s+= "templ_dir: " + c.templ_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+= "max_size: " + string(c.max_size) + "\n"
s+= "log_file: " + c.log_file + "\n"
return s return s
@ -93,8 +93,8 @@ func parse_config (fname string, c *Config) error {
c.paste_dir = strings.Trim(fields[1], " \t\"") c.paste_dir = strings.Trim(fields[1], " \t\"")
case "templ_dir": case "templ_dir":
c.templ_dir = strings.Trim(fields[1], " \t\"") c.templ_dir = strings.Trim(fields[1], " \t\"")
case "log_fname": case "log_file":
c.log_fname = strings.Trim(fields[1], " \t\"") c.log_file = strings.Trim(fields[1], " \t\"")
case "max_size": case "max_size":
if m_size, err := strconv.ParseUint(fields[1], 10, 16); err == nil { if m_size, err := strconv.ParseUint(fields[1], 10, 16); err == nil {
c.max_size = uint16(m_size) c.max_size = uint16(m_size)

@ -43,8 +43,8 @@ var p_conf = Config{
bind_port: "8000", bind_port: "8000",
paste_dir: "./pastes", paste_dir: "./pastes",
templ_dir: "./tmpl", templ_dir: "./tmpl",
log_fname: "./binnit.log",
max_size: 4096, max_size: 4096,
log_file: "./binnit.log",
} }
@ -171,9 +171,9 @@ func main() {
parse_config("binnit.cfg", &p_conf) 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 { 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) os.Exit(1)
} }
defer f.Close() defer f.Close()

Loading…
Cancel
Save