running go fmt

This commit is contained in:
Vincent Batts 2013-03-27 16:30:24 -04:00
parent 7ba7c07041
commit 9a5ded48a6
10 changed files with 906 additions and 925 deletions

119
client.go
View File

@ -1,75 +1,74 @@
package main package main
import ( import (
"bufio" "bufio"
"crypto/tls" "crypto/tls"
"io/ioutil" "io/ioutil"
"log" "log"
"mime" "mime"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
) )
func PutFileFromPath(host, filename string) (path string, err error) { func PutFileFromPath(host, filename string) (path string, err error) {
ext := filepath.Ext(filename) ext := filepath.Ext(filename)
file, err := os.Open(filename) file, err := os.Open(filename)
if (err != nil) { if err != nil {
return return
} }
resp, err := http.Post(host, mime.TypeByExtension(ext) , bufio.NewReader(file)) resp, err := http.Post(host, mime.TypeByExtension(ext), bufio.NewReader(file))
if (err != nil) { if err != nil {
return return
} }
bytes, err := ioutil.ReadAll(resp.Body) bytes, err := ioutil.ReadAll(resp.Body)
if (err != nil) { if err != nil {
return return
} }
return string(bytes), nil return string(bytes), nil
} }
func FetchFileFromURL(url string) (filename string, err error) { func FetchFileFromURL(url string) (filename string, err error) {
var t time.Time var t time.Time
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{ InsecureSkipVerify: true }, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }
client := &http.Client{ client := &http.Client{
//CheckRedirect: redirectPolicyFunc, //CheckRedirect: redirectPolicyFunc,
Transport: tr, Transport: tr,
} }
resp, err := client.Get(url) resp, err := client.Get(url)
defer resp.Body.Close() defer resp.Body.Close()
if (err != nil) { if err != nil {
return return
} }
mtime := resp.Header.Get("last-modified") mtime := resp.Header.Get("last-modified")
if (len(mtime) > 0) { if len(mtime) > 0 {
t, err = time.Parse(http.TimeFormat, mtime) t, err = time.Parse(http.TimeFormat, mtime)
if (err != nil) { if err != nil {
return return
} }
} else { } else {
log.Println("Last-Modified not present. Using current time") log.Println("Last-Modified not present. Using current time")
t = time.Now() t = time.Now()
} }
_, url_filename := filepath.Split(url) _, url_filename := filepath.Split(url)
log.Println(resp) log.Println(resp)
bytes, err := ioutil.ReadAll(resp.Body) bytes, err := ioutil.ReadAll(resp.Body)
if (err != nil) { if err != nil {
return return
} }
err = ioutil.WriteFile(filepath.Join(os.TempDir(), url_filename), bytes, 0644) err = ioutil.WriteFile(filepath.Join(os.TempDir(), url_filename), bytes, 0644)
if (err != nil) { if err != nil {
return return
} }
err = os.Chtimes(filepath.Join(os.TempDir(), url_filename), t, t) err = os.Chtimes(filepath.Join(os.TempDir(), url_filename), t, t)
// lastly, return // lastly, return
return filepath.Join(os.TempDir(), url_filename), nil return filepath.Join(os.TempDir(), url_filename), nil
} }

View File

@ -1,44 +1,45 @@
package main package main
import ( import (
"launchpad.net/goyaml" "io/ioutil"
"io/ioutil" "launchpad.net/goyaml"
) )
type Config map[string]interface{} type Config map[string]interface{}
func (c *Config) GetBool(option string) (value bool) { func (c *Config) GetBool(option string) (value bool) {
conf := Config{} conf := Config{}
conf = *c conf = *c
switch conf[option] { switch conf[option] {
default: value = false default:
case "yes", "on", "true": value = true value = false
} case "yes", "on", "true":
return value = true
}
return
} }
func (c *Config) GetString(option string) (value string) { func (c *Config) GetString(option string) (value string) {
conf := Config{} conf := Config{}
conf = *c conf = *c
value, _ = conf[option].(string) value, _ = conf[option].(string)
return return
} }
func ReadConfigFile(filename string) (config Config, err error) { func ReadConfigFile(filename string) (config Config, err error) {
bytes, err := ioutil.ReadFile(filename) bytes, err := ioutil.ReadFile(filename)
if (err != nil) { if err != nil {
return return
} }
err = goyaml.Unmarshal(bytes, &config) err = goyaml.Unmarshal(bytes, &config)
if (err != nil) { if err != nil {
return return
} }
return config, nil return config, nil
} }
func WriteConfigFile(filename string, data []byte) (err error) { func WriteConfigFile(filename string, data []byte) (err error) {
return return
} }

View File

@ -1,60 +1,58 @@
package main package main
import ( import (
"labix.org/v2/mgo/bson" "labix.org/v2/mgo/bson"
) )
/* gfs is a *mgo.GridFS defined in imgsrv.go */ /* gfs is a *mgo.GridFS defined in imgsrv.go */
func GetFileByFilename(filename string) (this_file File, err error) { func GetFileByFilename(filename string) (this_file File, err error) {
err = gfs.Find(bson.M{"filename":filename}).One(&this_file) err = gfs.Find(bson.M{"filename": filename}).One(&this_file)
if (err != nil) { if err != nil {
return this_file, err return this_file, err
} }
return this_file, nil return this_file, nil
} }
func GetFileRandom() (this_file File, err error) { func GetFileRandom() (this_file File, err error) {
r := Rand64() r := Rand64()
err = gfs.Find(bson.M{"random": bson.M{"$gt" : r } }).One(&this_file) err = gfs.Find(bson.M{"random": bson.M{"$gt": r}}).One(&this_file)
if (err != nil) { if err != nil {
return this_file, err return this_file, err
} }
if (len(this_file.Md5) == 0) { if len(this_file.Md5) == 0 {
err = gfs.Find(bson.M{"random": bson.M{"$lt" : r } }).One(&this_file) err = gfs.Find(bson.M{"random": bson.M{"$lt": r}}).One(&this_file)
} }
if (err != nil) { if err != nil {
return this_file, err return this_file, err
} }
return this_file, nil return this_file, nil
} }
/* Check whether this File filename is on Mongo */ /* Check whether this File filename is on Mongo */
func HasFileByFilename(filename string) (exists bool, err error) { func HasFileByFilename(filename string) (exists bool, err error) {
c, err := gfs.Find(bson.M{"filename": filename}).Count() c, err := gfs.Find(bson.M{"filename": filename}).Count()
if (err != nil) { if err != nil {
return false, err return false, err
} }
exists = (c > 0) exists = (c > 0)
return exists, nil return exists, nil
} }
func HasFileByMd5(md5 string) (exists bool, err error) { func HasFileByMd5(md5 string) (exists bool, err error) {
c, err := gfs.Find(bson.M{"md5": md5 }).Count() c, err := gfs.Find(bson.M{"md5": md5}).Count()
if (err != nil) { if err != nil {
return false, err return false, err
} }
exists = (c > 0) exists = (c > 0)
return exists, nil return exists, nil
} }
func HasFileByKeyword(keyword string) (exists bool, err error) { func HasFileByKeyword(keyword string) (exists bool, err error) {
c, err := gfs.Find(bson.M{"metadata": bson.M{"keywords": keyword} }).Count() c, err := gfs.Find(bson.M{"metadata": bson.M{"keywords": keyword}}).Count()
if (err != nil) { if err != nil {
return false, err return false, err
} }
exists = (c > 0) exists = (c > 0)
return exists, nil return exists, nil
} }

37
hash.go
View File

@ -1,38 +1,37 @@
package main package main
import ( import (
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"hash/adler32" "hash/adler32"
"io" "io"
"math/rand" "math/rand"
"time" "time"
) )
func Rand64() int64 { func Rand64() int64 {
return rand.Int63() return rand.Int63()
} }
/* Convinience method for getting md5 sum of a string */ /* Convinience method for getting md5 sum of a string */
func GetMd5FromString(blob string) (sum []byte) { func GetMd5FromString(blob string) (sum []byte) {
h := md5.New() h := md5.New()
defer h.Reset() defer h.Reset()
io.WriteString(h,blob) io.WriteString(h, blob)
return h.Sum(nil) return h.Sum(nil)
} }
/* Convinience method for getting md5 sum of some bytes */ /* Convinience method for getting md5 sum of some bytes */
func GetMd5FromBytes(blob []byte) (sum []byte) { func GetMd5FromBytes(blob []byte) (sum []byte) {
h := md5.New() h := md5.New()
defer h.Reset() defer h.Reset()
h.Write(blob) h.Write(blob)
return h.Sum(nil) return h.Sum(nil)
} }
/* get a small, decently unique hash */ /* get a small, decently unique hash */
func GetSmallHash() (small_hash string) { func GetSmallHash() (small_hash string) {
h := adler32.New() h := adler32.New()
io.WriteString(h, fmt.Sprintf("%d", time.Now().Unix())) io.WriteString(h, fmt.Sprintf("%d", time.Now().Unix()))
return fmt.Sprintf("%X", h.Sum(nil)) return fmt.Sprintf("%X", h.Sum(nil))
} }

View File

@ -1,40 +1,39 @@
package main package main
import ( import (
"fmt" "fmt"
"testing" "testing"
) )
func TestRand64(t *testing.T) { func TestRand64(t *testing.T) {
var i interface{} var i interface{}
i = Rand64() i = Rand64()
v, ok := i.(int64) v, ok := i.(int64)
if (!ok) { if !ok {
t.Errorf("Rand64 returned wrong type") t.Errorf("Rand64 returned wrong type")
} }
if (v < 0) { if v < 0 {
t.Errorf("Rand64 returned a too small number [%d]", v) t.Errorf("Rand64 returned a too small number [%d]", v)
} }
} }
func TestMd5Bytes(t *testing.T) { func TestMd5Bytes(t *testing.T) {
var blob = []byte("Hurp til you Derp") var blob = []byte("Hurp til you Derp")
var expected = "3ef08fa896a154eee3c97f037c9d6dfc" var expected = "3ef08fa896a154eee3c97f037c9d6dfc"
var actual = fmt.Sprintf("%x", GetMd5FromBytes(blob)) var actual = fmt.Sprintf("%x", GetMd5FromBytes(blob))
if (actual != expected) { if actual != expected {
t.Errorf("Md5FromBytes sum did not match! %s != %s",actual,expected) t.Errorf("Md5FromBytes sum did not match! %s != %s", actual, expected)
} }
} }
func TestMd5String(t *testing.T) { func TestMd5String(t *testing.T) {
var blob = "Hurp til you Derp" var blob = "Hurp til you Derp"
var expected = "3ef08fa896a154eee3c97f037c9d6dfc" var expected = "3ef08fa896a154eee3c97f037c9d6dfc"
var actual = fmt.Sprintf("%x", GetMd5FromString(blob)) var actual = fmt.Sprintf("%x", GetMd5FromString(blob))
if (actual != expected) { if actual != expected {
t.Errorf("Md5FromString sum did not match! %s != %s",actual,expected) t.Errorf("Md5FromString sum did not match! %s != %s", actual, expected)
} }
} }
func TestHash(t *testing.T) { func TestHash(t *testing.T) {
} }

339
imgsrv.go
View File

@ -8,201 +8,200 @@ package main
*/ */
import ( import (
"flag" "flag"
"fmt" "fmt"
"labix.org/v2/mgo" "labix.org/v2/mgo"
"log" "log"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
) )
var ( var (
ConfigFile = fmt.Sprintf("%s/.imgsrv.yaml", os.Getenv("HOME")) ConfigFile = fmt.Sprintf("%s/.imgsrv.yaml", os.Getenv("HOME"))
DefaultRunAsServer = false DefaultRunAsServer = false
RunAsServer = DefaultRunAsServer RunAsServer = DefaultRunAsServer
DefaultServerIP = "0.0.0.0" DefaultServerIP = "0.0.0.0"
ServerIP = DefaultServerIP ServerIP = DefaultServerIP
DefaultServerPort = "7777" DefaultServerPort = "7777"
ServerPort = DefaultServerPort ServerPort = DefaultServerPort
DefaultMongoHost = "localhost" DefaultMongoHost = "localhost"
MongoHost = DefaultMongoHost MongoHost = DefaultMongoHost
DefaultMongoDB = "filesrv" DefaultMongoDB = "filesrv"
MongoDB = DefaultMongoDB MongoDB = DefaultMongoDB
DefaultMongoUsername = "" DefaultMongoUsername = ""
MongoUsername = DefaultMongoUsername MongoUsername = DefaultMongoUsername
DefaultMongoPassword = "" DefaultMongoPassword = ""
MongoPassword = DefaultMongoPassword MongoPassword = DefaultMongoPassword
mongo_session *mgo.Session mongo_session *mgo.Session
images_db *mgo.Database images_db *mgo.Database
gfs *mgo.GridFS gfs *mgo.GridFS
DefaultRemoteHost = "" DefaultRemoteHost = ""
RemoteHost = DefaultRemoteHost RemoteHost = DefaultRemoteHost
PutFile = "" PutFile = ""
FetchUrl = "" FetchUrl = ""
FileKeywords = "" FileKeywords = ""
) )
func main() { func main() {
flag.Parse() flag.Parse()
for _, arg := range flag.Args() { for _, arg := range flag.Args() {
// What to do with these floating args ... // What to do with these floating args ...
log.Printf("%s", arg) log.Printf("%s", arg)
} }
// loads either default or flag specified config // loads either default or flag specified config
// to override variables // to override variables
loadConfiguration(ConfigFile) loadConfiguration(ConfigFile)
if (len(FetchUrl) > 0) { if len(FetchUrl) > 0 {
file, err := FetchFileFromURL(FetchUrl) file, err := FetchFileFromURL(FetchUrl)
if (err != nil) { if err != nil {
log.Println(err) log.Println(err)
return return
} }
log.Println(file) log.Println(file)
} else if (RunAsServer) { } else if RunAsServer {
log.Printf("%s", ServerIP) log.Printf("%s", ServerIP)
runServer(ServerIP,ServerPort) runServer(ServerIP, ServerPort)
} else { } else {
if (len(RemoteHost) == 0) { if len(RemoteHost) == 0 {
log.Println("Please provide a remotehost!") log.Println("Please provide a remotehost!")
return return
} }
if (len(PutFile) == 0 ) { //&& len(flag.Args()) == 0) { if len(PutFile) == 0 { //&& len(flag.Args()) == 0) {
log.Println("Please provide files to be uploaded!") log.Println("Please provide files to be uploaded!")
return return
} }
_,basename := filepath.Split(PutFile) _, basename := filepath.Split(PutFile)
queryParams := "?filename=" + basename queryParams := "?filename=" + basename
if (len(FileKeywords) > 0) { if len(FileKeywords) > 0 {
queryParams = queryParams + "&keywords=" + FileKeywords queryParams = queryParams + "&keywords=" + FileKeywords
} else { } else {
log.Println("WARN: you didn't provide any keywords :-(") log.Println("WARN: you didn't provide any keywords :-(")
} }
url, err := url.Parse(RemoteHost + "/f/" + queryParams) url, err := url.Parse(RemoteHost + "/f/" + queryParams)
if (err != nil) { if err != nil {
log.Println(err) log.Println(err)
return return
} }
log.Printf("POSTing: %s\n", url.String()) log.Printf("POSTing: %s\n", url.String())
url_path, err := PutFileFromPath(url.String(), PutFile) url_path, err := PutFileFromPath(url.String(), PutFile)
if (err != nil) { if err != nil {
log.Println(err) log.Println(err)
return return
} }
log.Printf("New Image!: %s%s\n", RemoteHost, url_path) log.Printf("New Image!: %s%s\n", RemoteHost, url_path)
} }
} }
/* http://golang.org/doc/effective_go.html#init */ /* http://golang.org/doc/effective_go.html#init */
func init() { func init() {
flag.StringVar(&ConfigFile, flag.StringVar(&ConfigFile,
"config", "config",
ConfigFile, ConfigFile,
"Provide alternate configuration file") "Provide alternate configuration file")
/* Server-side */ /* Server-side */
flag.BoolVar(&RunAsServer, flag.BoolVar(&RunAsServer,
"server", "server",
RunAsServer, RunAsServer,
"Run as an image server (defaults to client-side)") "Run as an image server (defaults to client-side)")
flag.StringVar(&ServerIP, flag.StringVar(&ServerIP,
"ip", "ip",
ServerIP, ServerIP,
"IP to bind to (if running as a server)('ip' in the config)") "IP to bind to (if running as a server)('ip' in the config)")
flag.StringVar(&ServerPort, flag.StringVar(&ServerPort,
"port", "port",
ServerPort, ServerPort,
"Port to listen on (if running as a server)('port' in the config)") "Port to listen on (if running as a server)('port' in the config)")
/* MongoDB settings */ /* MongoDB settings */
flag.StringVar(&MongoHost, flag.StringVar(&MongoHost,
"mongo-host", "mongo-host",
MongoHost, MongoHost,
"Mongo Host to connect to ('mongohost' in the config)") "Mongo Host to connect to ('mongohost' in the config)")
flag.StringVar(&MongoDB, flag.StringVar(&MongoDB,
"mongo-db", "mongo-db",
MongoDB, MongoDB,
"Mongo db to connect to ('mongodb' in the config)") "Mongo db to connect to ('mongodb' in the config)")
flag.StringVar(&MongoUsername, flag.StringVar(&MongoUsername,
"mongo-username", "mongo-username",
MongoUsername, MongoUsername,
"Mongo username to auth with (if needed) ('mongousername' in the config)") "Mongo username to auth with (if needed) ('mongousername' in the config)")
flag.StringVar(&MongoPassword, flag.StringVar(&MongoPassword,
"mongo-password", "mongo-password",
MongoPassword, MongoPassword,
"Mongo password to auth with (if needed) ('mongopassword' in the config)") "Mongo password to auth with (if needed) ('mongopassword' in the config)")
/* Client-side */ /* Client-side */
flag.StringVar(&FetchUrl, flag.StringVar(&FetchUrl,
"fetch", "fetch",
FetchUrl, FetchUrl,
"Just fetch the file from this url") "Just fetch the file from this url")
flag.StringVar(&RemoteHost, flag.StringVar(&RemoteHost,
"remotehost", "remotehost",
RemoteHost, RemoteHost,
"Remote host to get/put files on ('remotehost' in the config)") "Remote host to get/put files on ('remotehost' in the config)")
flag.StringVar(&PutFile, flag.StringVar(&PutFile,
"put", "put",
PutFile, PutFile,
"Put file on remote server (needs -remotehost)") "Put file on remote server (needs -remotehost)")
flag.StringVar(&FileKeywords, flag.StringVar(&FileKeywords,
"keywords", "keywords",
FileKeywords, FileKeywords,
"Keywords to associate with file. (comma delimited) (needs -put)") "Keywords to associate with file. (comma delimited) (needs -put)")
} }
func loadConfiguration(filename string) (c Config) { func loadConfiguration(filename string) (c Config) {
//log.Printf("Attempting to load config file: %s", filename) //log.Printf("Attempting to load config file: %s", filename)
c, err := ReadConfigFile(filename) c, err := ReadConfigFile(filename)
if (err != nil) { if err != nil {
//log.Println(err) //log.Println(err)
return Config{} return Config{}
} }
cRunAsServer := c.GetBool("server") cRunAsServer := c.GetBool("server")
cServerIp := c.GetString("ip") cServerIp := c.GetString("ip")
cServerPort := c.GetString("port") cServerPort := c.GetString("port")
cMongoHost := c.GetString("mongohost") cMongoHost := c.GetString("mongohost")
cMongoDB := c.GetString("mongodb") cMongoDB := c.GetString("mongodb")
cMongoUsername := c.GetString("mongousername") cMongoUsername := c.GetString("mongousername")
cMongoPassword := c.GetString("mongopassword") cMongoPassword := c.GetString("mongopassword")
cRemoteHost := c.GetString("remotehost") cRemoteHost := c.GetString("remotehost")
// Only set variables from config file, // Only set variables from config file,
// if they weren't passed as flags // if they weren't passed as flags
if (DefaultRunAsServer == RunAsServer && cRunAsServer) { if DefaultRunAsServer == RunAsServer && cRunAsServer {
RunAsServer = cRunAsServer RunAsServer = cRunAsServer
} }
if (DefaultServerIP == ServerIP && len(cServerIp) > 0) { if DefaultServerIP == ServerIP && len(cServerIp) > 0 {
ServerIP = cServerIp ServerIP = cServerIp
} }
if (DefaultServerPort == ServerPort && len(cServerPort) > 0) { if DefaultServerPort == ServerPort && len(cServerPort) > 0 {
ServerPort = cServerPort ServerPort = cServerPort
} }
if (DefaultMongoHost == MongoHost && len(cMongoHost) > 0) { if DefaultMongoHost == MongoHost && len(cMongoHost) > 0 {
MongoHost = cMongoHost MongoHost = cMongoHost
} }
if (DefaultMongoDB == MongoDB && len(cMongoDB) > 0) { if DefaultMongoDB == MongoDB && len(cMongoDB) > 0 {
MongoDB = cMongoDB MongoDB = cMongoDB
} }
if (DefaultMongoUsername == MongoUsername && len(cMongoUsername) > 0) { if DefaultMongoUsername == MongoUsername && len(cMongoUsername) > 0 {
MongoUsername = cMongoUsername MongoUsername = cMongoUsername
} }
if (DefaultMongoPassword == MongoPassword && len(cMongoPassword) > 0) { if DefaultMongoPassword == MongoPassword && len(cMongoPassword) > 0 {
MongoPassword = cMongoPassword MongoPassword = cMongoPassword
} }
if (DefaultRemoteHost == RemoteHost && len(cRemoteHost) > 0) { if DefaultRemoteHost == RemoteHost && len(cRemoteHost) > 0 {
RemoteHost = cRemoteHost RemoteHost = cRemoteHost
} }
return c return c
} }

View File

@ -1,14 +1,13 @@
package main package main
import ( import (
"fmt" "fmt"
"io" "io"
"text/template" "text/template"
) )
var emptyInterface interface{} var emptyInterface interface{}
var headTemplate = template.Must(template.New("head").Parse(headTemplateHTML)) var headTemplate = template.Must(template.New("head").Parse(headTemplateHTML))
var headTemplateHTML = ` var headTemplateHTML = `
<html> <html>
@ -128,86 +127,76 @@ var listTemplateHTML = `
` `
func UrliePage(w io.Writer) (err error) { func UrliePage(w io.Writer) (err error) {
err = headTemplate.Execute(w, map[string]string{"title" : "FileSrv :: URLie"}) err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: URLie"})
if (err != nil) { if err != nil {
return err return err
} }
err = navbarTemplate.Execute(w, nil) err = navbarTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = containerBeginTemplate.Execute(w, nil) err = containerBeginTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = formGetUrlTemplate.Execute(w, &emptyInterface) err = formGetUrlTemplate.Execute(w, &emptyInterface)
if (err != nil) { if err != nil {
return err return err
} }
err = tailTemplate.Execute(w, map[string]string{"footer" : fmt.Sprintf("Version: %s", VERSION)}) err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
if (err != nil) { if err != nil {
return err return err
} }
return return
} }
func UploadPage(w io.Writer) (err error) { func UploadPage(w io.Writer) (err error) {
err = headTemplate.Execute(w, map[string]string{"title" : "FileSrv :: Upload"}) err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: Upload"})
if (err != nil) { if err != nil {
return err return err
} }
err = navbarTemplate.Execute(w, nil) err = navbarTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = containerBeginTemplate.Execute(w, nil) err = containerBeginTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = formFileUploadTemplate.Execute(w, &emptyInterface) err = formFileUploadTemplate.Execute(w, &emptyInterface)
if (err != nil) { if err != nil {
return err return err
} }
err = tailTemplate.Execute(w, map[string]string{"footer" : fmt.Sprintf("Version: %s", VERSION)}) err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
if (err != nil) { if err != nil {
return err return err
} }
return return
} }
func ListFilesPage(w io.Writer, files []File) (err error) { func ListFilesPage(w io.Writer, files []File) (err error) {
err = headTemplate.Execute(w, map[string]string{"title" : "FileSrv"}) err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
if (err != nil) { if err != nil {
return err return err
} }
err = navbarTemplate.Execute(w, nil) err = navbarTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = containerBeginTemplate.Execute(w, nil) err = containerBeginTemplate.Execute(w, nil)
if (err != nil) { if err != nil {
return err return err
} }
err = listTemplate.Execute(w, files) err = listTemplate.Execute(w, files)
if (err != nil) { if err != nil {
return err return err
} }
err = tailTemplate.Execute(w, map[string]string{"footer" : fmt.Sprintf("Version: %s", VERSION)}) err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
if (err != nil) { if err != nil {
return err return err
} }
return return
} }
var bootstrapCSS = ` var bootstrapCSS = `
/*! /*!
* Bootstrap v2.2.2 * Bootstrap v2.2.2
@ -6249,5 +6238,3 @@ a.badge:hover {
position: fixed; position: fixed;
} }
` `

989
server.go

File diff suppressed because it is too large Load Diff

View File

@ -3,18 +3,18 @@ package main
import "time" import "time"
type Info struct { type Info struct {
Keywords []string // tags Keywords []string // tags
Ip string // who uploaded it Ip string // who uploaded it
Random int64 Random int64
TimeStamp time.Time "timestamp,omitempty" TimeStamp time.Time "timestamp,omitempty"
} }
type File struct { type File struct {
Metadata Info ",omitempty" Metadata Info ",omitempty"
Md5 string Md5 string
ChunkSize int ChunkSize int
UploadDate time.Time UploadDate time.Time
Length int64 Length int64
Filename string ",omitempty" Filename string ",omitempty"
ContentType string "contentType,omitempty" ContentType string "contentType,omitempty"
} }

View File

@ -1,12 +1,12 @@
package main package main
import ( import (
"fmt" "fmt"
) )
var ( var (
MAJOR int = 1 MAJOR int = 1
MINOR int = 0 MINOR int = 0
TINY int = 0 TINY int = 0
VERSION string = fmt.Sprintf("%d.%d.%d", MAJOR, MINOR, TINY) VERSION string = fmt.Sprintf("%d.%d.%d", MAJOR, MINOR, TINY)
) )