1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
var httpFileSystemFix = fix{
15
`Adapt http FileServer to take a FileSystem.
17
http://codereview.appspot.com/4629047 http FileSystem interface
22
register(httpFileSystemFix)
25
func httpfs(f *ast.File) bool {
26
if !imports(f, "http") {
31
walk(f, func(n interface{}) {
32
call, ok := n.(*ast.CallExpr)
33
if !ok || !isPkgDot(call.Fun, "http", "FileServer") {
36
if len(call.Args) != 2 {
39
dir, prefix := call.Args[0], call.Args[1]
40
call.Args = []ast.Expr{&ast.CallExpr{
41
Fun: &ast.SelectorExpr{ast.NewIdent("http"), ast.NewIdent("Dir")},
42
Args: []ast.Expr{dir},
44
wrapInStripHandler := true
45
if prefixLit, ok := prefix.(*ast.BasicLit); ok {
46
if prefixLit.Kind == token.STRING && (prefixLit.Value == `"/"` || prefixLit.Value == `""`) {
47
wrapInStripHandler = false
50
if wrapInStripHandler {
51
call.Fun.(*ast.SelectorExpr).Sel = ast.NewIdent("StripPrefix")
52
call.Args = []ast.Expr{
55
Fun: &ast.SelectorExpr{ast.NewIdent("http"), ast.NewIdent("FileServer")},