mirror of
https://github.com/nxshock/simplefileshare.git
synced 2025-07-02 00:13:36 +05:00
Import project
This commit is contained in:
parent
f0e39831c2
commit
1b0cbbf5cd
13 changed files with 588 additions and 0 deletions
53
main.go
Normal file
53
main.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetOutput(os.Stderr)
|
||||
log.SetFormatter(&logrus.TextFormatter{ForceColors: true, DisableTimestamp: true})
|
||||
log.SetLevel(log.ErrorLevel)
|
||||
|
||||
err := initConfig()
|
||||
if err != nil {
|
||||
log.Fatalln("initConfig:", err)
|
||||
}
|
||||
|
||||
log.SetLevel(config.LogLevel)
|
||||
|
||||
err = initTemplates()
|
||||
if err != nil {
|
||||
log.Fatalln("initTemplates:", err)
|
||||
}
|
||||
|
||||
if config.RemoveFilePeriod > 0 {
|
||||
go removeOldFilesThread(config.StoragePath, time.Duration(config.RemoveFilePeriod)*time.Hour)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", HandleRoot)
|
||||
http.HandleFunc("/upload", HandleUpload)
|
||||
http.HandleFunc("/download", HandleDownload)
|
||||
}
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
err := http.ListenAndServe(config.ListenAddress, nil)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
<-c
|
||||
log.Debugln("Stop signal received.")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue