gofmt -s -w main.go
This commit is contained in:
parent
ce13cbd675
commit
4e66c88944
14
main.go
14
main.go
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// mtmediasrv - a Minetest Media server implementation done right
|
// mtmediasrv - a Minetest Media server implementation done right
|
||||||
//
|
//
|
||||||
@ -25,6 +24,7 @@ import (
|
|||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/spf13/viper"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -34,10 +34,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version string
|
Version string
|
||||||
Build string
|
Build string
|
||||||
@ -61,7 +59,7 @@ func (s FastCGIServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
log.Print("Request: invalid header\n")
|
log.Print("Request: invalid header\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(version, []byte {0, 1}) {
|
if !bytes.Equal(version, []byte{0, 1}) {
|
||||||
log.Print("Request: unsupported version\n")
|
log.Print("Request: unsupported version\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -91,7 +89,7 @@ func (s FastCGIServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
// formulate response
|
// formulate response
|
||||||
headers := w.Header()
|
headers := w.Header()
|
||||||
headers.Add("Content-Type", "octet/stream")
|
headers.Add("Content-Type", "octet/stream")
|
||||||
headers.Add("Content-Length", fmt.Sprintf("%d", 6 + (len(resultarr) * 20)))
|
headers.Add("Content-Length", fmt.Sprintf("%d", 6+(len(resultarr)*20)))
|
||||||
|
|
||||||
c1, _ := w.Write([]byte(header))
|
c1, _ := w.Write([]byte(header))
|
||||||
c2, _ := w.Write([]byte(version))
|
c2, _ := w.Write([]byte(version))
|
||||||
@ -128,7 +126,7 @@ func parseMedia(path string) {
|
|||||||
arr = make([]string, 0)
|
arr = make([]string, 0)
|
||||||
files, _ := ioutil.ReadDir(path)
|
files, _ := ioutil.ReadDir(path)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
h, err := getHash(strings.Join([]string{path, "/" , f.Name()}, ""))
|
h, err := getHash(strings.Join([]string{path, "/", f.Name()}, ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("parseMedia(): ", f.Name(), err)
|
log.Print("parseMedia(): ", f.Name(), err)
|
||||||
continue
|
continue
|
||||||
@ -202,7 +200,7 @@ func main() {
|
|||||||
viper.SetDefault("mediascan", "true")
|
viper.SetDefault("mediascan", "true")
|
||||||
viper.SetDefault("medialink", "true")
|
viper.SetDefault("medialink", "true")
|
||||||
viper.SetDefault("mediacopy", "false")
|
viper.SetDefault("mediacopy", "false")
|
||||||
viper.SetDefault("extensions", []string{ ".png", ".jpg", ".jpeg", ".ogg", ".x", ".b3d", ".obj"})
|
viper.SetDefault("extensions", []string{".png", ".jpg", ".jpeg", ".ogg", ".x", ".b3d", ".obj"})
|
||||||
|
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -219,7 +217,7 @@ func main() {
|
|||||||
if viper.GetBool("mediascan") {
|
if viper.GetBool("mediascan") {
|
||||||
l := viper.GetBool("medialink")
|
l := viper.GetBool("medialink")
|
||||||
c := viper.GetBool("mediacopy")
|
c := viper.GetBool("mediacopy")
|
||||||
if (!(l || c)) {
|
if !(l || c) {
|
||||||
log.Fatal("mediascan enabled but both medialink and mediacopy are disabled!")
|
log.Fatal("mediascan enabled but both medialink and mediacopy are disabled!")
|
||||||
}
|
}
|
||||||
if len(viper.GetStringSlice("mediapath")) == 0 {
|
if len(viper.GetStringSlice("mediapath")) == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user