summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-06-30 23:15:36 +0100
committerKatolaZ <katolaz@freaknet.org>2017-06-30 23:15:36 +0100
commitee3dc59322eb3a366f3594261491381db5084110 (patch)
treefa3a98639cf8c38f80c42fe00f1f8abb0562d200 /main.go
parentcfc67a824600be8d522c23c108d6333fca6b0359 (diff)
Added max_size in the configuration file
Diffstat (limited to 'main.go')
-rw-r--r--main.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/main.go b/main.go
index cd50525..aa34a5f 100644
--- a/main.go
+++ b/main.go
@@ -19,10 +19,20 @@ var p_conf = Config{
paste_dir: "./pastes",
templ_dir: "./tmpl",
log_fname: "./binit.log",
+ max_size: 4096,
}
+func min (a, b int) int {
+
+ if a > b {
+ return b
+ } else {
+ return a
+ }
+
+}
func handle_get_paste(w http.ResponseWriter, r *http.Request) {
@@ -70,6 +80,9 @@ func handle_put_paste(w http.ResponseWriter, r *http.Request) {
paste := req_body.Get("paste")
now := time.Now().String()
// format content
+
+ paste = paste[0:min(len(paste), int(p_conf.max_size))]
+
content := fmt.Sprintf("# Title: %s\n# Pasted: %s\n------------\n%s", title, now, paste)
// ccompute the sha256 hash using title, body, and time
@@ -138,6 +151,7 @@ func main() {
log.Printf(" + listening on: %s:%s\n", p_conf.host, p_conf.port )
log.Printf(" + paste_dir: %s\n", p_conf.paste_dir)
log.Printf(" + templ_dir: %s\n", p_conf.templ_dir)
+ log.Printf(" + max_size: %d\n", p_conf.max_size)
http.HandleFunc("/", req_handler)