| // Copyright 2017 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func fossilHandler() http.Handler { |
| return http.HandlerFunc(fossilDispatch) |
| func fossilDispatch(w http.ResponseWriter, r *http.Request) { |
| if !strings.HasPrefix(r.URL.Path, "/fossil/") { |
| name := strings.TrimPrefix(r.URL.Path, "/fossil/") |
| if i := strings.Index(name, "/"); i >= 0 { |
| db := filepath.Join(*dir, "fossil/"+name+"/"+name+".fossil") |
| if _, err := os.Stat(db + ".cgi"); err != nil { |
| ioutil.WriteFile(db+".cgi", []byte("#!/usr/bin/fossil\nrepository: "+db+"\n"), 0777) |
| Dir: filepath.Join(*dir, "fossil"), |