diff --git a/assets/index.html b/assets/index.html index e22220b..2dc0e88 100644 --- a/assets/index.html +++ b/assets/index.html @@ -64,6 +64,8 @@ [[end]] + + [[if not .NoIndex ]]
+ [[end]] diff --git a/httpstaticserver.go b/httpstaticserver.go index 4e4e182..694ef59 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -58,13 +58,14 @@ type HTTPStaticServer struct { GoogleTrackerID string AuthType string DeepPathMaxDepth int + NoIndex bool indexes []IndexFileItem m *mux.Router bufPool sync.Pool // use sync.Pool caching buf to reduce gc ratio } -func NewHTTPStaticServer(root string) *HTTPStaticServer { +func NewHTTPStaticServer(root string, noIndex bool) *HTTPStaticServer { // if root == "" { // root = "./" // } @@ -82,20 +83,23 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer { bufPool: sync.Pool{ New: func() interface{} { return make([]byte, 32*1024) }, }, + NoIndex: noIndex, + } + + if !noIndex { + go func() { + time.Sleep(1 * time.Second) + for { + startTime := time.Now() + log.Println("Started making search index") + s.makeIndex() + log.Printf("Completed search index in %v", time.Since(startTime)) + //time.Sleep(time.Second * 1) + time.Sleep(time.Minute * 10) + } + }() } - go func() { - time.Sleep(1 * time.Second) - for { - startTime := time.Now() - log.Println("Started making search index") - s.makeIndex() - log.Printf("Completed search index in %v", time.Since(startTime)) - //time.Sleep(time.Second * 1) - time.Sleep(time.Minute * 10) - } - }() - // routers for Apple *.ipa m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist) m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink) diff --git a/main.go b/main.go index 17c679c..c78f96e 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,8 @@ type Configure struct { ID string `yaml:"id"` // for oauth2 Secret string `yaml:"secret"` // for oauth2 } `yaml:"auth"` - DeepPathMaxDepth int `yaml:"deep-path-max-depth"` + DeepPathMaxDepth int `yaml:"deep-path-max-depth"` + NoIndex bool `yaml:"no-index"` } type httpLogger struct{} @@ -100,6 +101,7 @@ func parseFlags() error { gcfg.GoogleTrackerID = "UA-81205425-2" gcfg.Title = "Go HTTP File Server" gcfg.DeepPathMaxDepth = 5 + gcfg.NoIndex = false kingpin.HelpFlag.Short('h') kingpin.Version(versionMessage()) @@ -122,6 +124,7 @@ func parseFlags() error { kingpin.Flag("title", "server title").StringVar(&gcfg.Title) kingpin.Flag("google-tracker-id", "set to empty to disable it").StringVar(&gcfg.GoogleTrackerID) kingpin.Flag("deep-path-max-depth", "set to -1 to not combine dirs").IntVar(&gcfg.DeepPathMaxDepth) + kingpin.Flag("no-index", "disable indexing").BoolVar(&gcfg.NoIndex) kingpin.Parse() // first parse conf @@ -178,7 +181,7 @@ func main() { log.Printf("url prefix: %s", gcfg.Prefix) } - ss := NewHTTPStaticServer(gcfg.Root) + ss := NewHTTPStaticServer(gcfg.Root, gcfg.NoIndex) ss.Prefix = gcfg.Prefix ss.Theme = gcfg.Theme ss.Title = gcfg.Title