Changeset 31 in code for trunk/partage.go


Ignore:
Timestamp:
Oct 19, 2021, 10:20:42 AM (4 years ago)
Author:
dev
Message:

Reformat code with go fmt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/partage.go

    r30 r31  
    22
    33import (
     4        "encoding/json"
     5        "flag"
    46        "fmt"
    5         "flag"
     7        "html/template"
    68        "io"
    79        "io/ioutil"
     
    1012        "os"
    1113        "os/user"
     14        "path"
     15        "path/filepath"
     16        "strconv"
     17        "syscall"
    1218        "time"
    13         "path"
    14         "syscall"
    15         "strconv"
    16         "path/filepath"
    17         "html/template"
    18         "encoding/json"
    1919
    2020        "github.com/dustin/go-humanize"
     
    2323
    2424type templatedata struct {
    25         Links []string
    26         Size string
     25        Links   []string
     26        Size    string
    2727        Maxsize string
    2828}
     
    3030type metadata struct {
    3131        Filename string
    32         Size int64
    33         Expiry int64
     32        Size     int64
     33        Expiry   int64
    3434}
    3535
    3636var conf struct {
    37         user        string
    38         group       string
    39         chroot      string
    40         bind        string
    41         baseuri     string
    42         rootdir     string
    43         tmplpath    string
    44         filepath    string
    45         metapath    string
    46         filectx     string
    47         metactx     string
    48         maxsize     int64
    49         expiry      int64
     37        user     string
     38        group    string
     39        chroot   string
     40        bind     string
     41        baseuri  string
     42        rootdir  string
     43        tmplpath string
     44        filepath string
     45        metapath string
     46        filectx  string
     47        metactx  string
     48        maxsize  int64
     49        expiry   int64
    5050}
    5151
     
    9393        meta := metadata{
    9494                Filename: filepath.Base(filename),
    95                 Size: size,
    96                 Expiry: time.Now().Unix() + expiry,
    97         }
    98 
    99         if verbose {
    100                 log.Printf("Saving metadata for %s in %s", meta.Filename, conf.metapath + "/" + meta.Filename + ".json")
     95                Size:     size,
     96                Expiry:   time.Now().Unix() + expiry,
     97        }
     98
     99        if verbose {
     100                log.Printf("Saving metadata for %s in %s", meta.Filename, conf.metapath+"/"+meta.Filename+".json")
    101101        }
    102102
     
    197197                writemeta(tmp.Name(), conf.expiry)
    198198
    199 
    200199                link := conf.baseuri + conf.filectx + filepath.Base(tmp.Name())
    201200                links = append(links, link)
    202201        }
    203202
    204         if (r.PostFormValue("output") == "html") {
    205                 data := templatedata{ Links: links }
     203        if r.PostFormValue("output") == "html" {
     204                data := templatedata{Links: links}
    206205                servetemplate(w, "/upload.html", data)
    207206                return
     
    217216        filename := r.URL.Path
    218217        if r.URL.Path == "/" || r.URL.Path == "/index.html" {
    219                 data := templatedata{ Maxsize: humanize.IBytes(uint64(conf.maxsize))}
     218                data := templatedata{Maxsize: humanize.IBytes(uint64(conf.maxsize))}
    220219                servetemplate(w, "/index.html", data)
    221220                return
     
    223222
    224223        if verbose {
    225                 log.Printf("Serving file %s", conf.rootdir + filename)
    226         }
    227 
    228         http.ServeFile(w, r, conf.rootdir + filename)
     224                log.Printf("Serving file %s", conf.rootdir+filename)
     225        }
     226
     227        http.ServeFile(w, r, conf.rootdir+filename)
    229228}
    230229
     
    246245func main() {
    247246        var file string
    248         flag.StringVar(&file,  "f", "", "Configuration file")
     247        flag.StringVar(&file, "f", "", "Configuration file")
    249248        flag.BoolVar(&verbose, "v", false, "Verbose logging")
    250249        flag.Parse()
    251250
    252251        /* default values */
    253         conf.bind     = "0.0.0.0:8080"
    254         conf.baseuri  = "http://127.0.0.1:8080"
    255         conf.rootdir  = "/htdocs"
     252        conf.bind = "0.0.0.0:8080"
     253        conf.baseuri = "http://127.0.0.1:8080"
     254        conf.rootdir = "/htdocs"
    256255        conf.tmplpath = "/htdocs/templates"
    257256        conf.filepath = "/htdocs/files"
    258257        conf.metapath = "/htdocs/meta"
    259         conf.filectx  = "/f/"
    260         conf.metactx  = "/m/"
    261         conf.maxsize  = 34359738368
    262         conf.expiry   = 86400
     258        conf.filectx = "/f/"
     259        conf.metactx = "/m/"
     260        conf.maxsize = 34359738368
     261        conf.expiry = 86400
    263262
    264263        if file != "" {
     
    273272                }
    274273
    275                 conf.bind        = cfg.Section("").Key("bind").String()
    276                 conf.user        = cfg.Section("").Key("user").String()
    277                 conf.group       = cfg.Section("").Key("group").String()
    278                 conf.baseuri     = cfg.Section("").Key("baseuri").String()
    279                 conf.filepath    = cfg.Section("").Key("filepath").String()
    280                 conf.metapath    = cfg.Section("").Key("metapath").String()
    281                 conf.filectx     = cfg.Section("").Key("filectx").String()
    282                 conf.metactx     = cfg.Section("").Key("metactx").String()
    283                 conf.rootdir     = cfg.Section("").Key("rootdir").String()
    284                 conf.chroot      = cfg.Section("").Key("chroot").String()
    285                 conf.tmplpath    = cfg.Section("").Key("tmplpath").String()
    286                 conf.maxsize, _  = cfg.Section("").Key("maxsize").Int64()
    287                 conf.expiry, _   = cfg.Section("").Key("expiry").Int64()
     274                conf.bind = cfg.Section("").Key("bind").String()
     275                conf.user = cfg.Section("").Key("user").String()
     276                conf.group = cfg.Section("").Key("group").String()
     277                conf.baseuri = cfg.Section("").Key("baseuri").String()
     278                conf.filepath = cfg.Section("").Key("filepath").String()
     279                conf.metapath = cfg.Section("").Key("metapath").String()
     280                conf.filectx = cfg.Section("").Key("filectx").String()
     281                conf.metactx = cfg.Section("").Key("metactx").String()
     282                conf.rootdir = cfg.Section("").Key("rootdir").String()
     283                conf.chroot = cfg.Section("").Key("chroot").String()
     284                conf.tmplpath = cfg.Section("").Key("tmplpath").String()
     285                conf.maxsize, _ = cfg.Section("").Key("maxsize").Int64()
     286                conf.expiry, _ = cfg.Section("").Key("expiry").Int64()
    288287        }
    289288
     
    292291        }
    293292
    294         if (conf.chroot != "") {
     293        if conf.chroot != "" {
    295294                if verbose {
    296295                        log.Printf("Changing root to %s", conf.chroot)
Note: See TracChangeset for help on using the changeset viewer.