// FileServer file server that disabled file listing
13495
func FileServer(dir http.Dir) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		p := path.Join(string(dir), r.URL.Path)
		if f, err := os.Stat(p); err == nil && !f.IsDir() {
			http.ServeFile(w, r, p)
			return
		}

		http.NotFound(w, r)
	})
}
3296
func (s *Service) ListDir(ctx context.Context, q *ListDirRequest) (*FileList, error) {
	gitClient, commitSHA, err := s.newClientResolveRevision(q.Repo, q.Revision)
	if err != nil {
		return nil, err
	}
	if files, err := s.cache.GetGitListDir(commitSHA, q.Path); err == nil {
		log.Infof("listdir cache hit: %s/%s", commitSHA, q.Path)
		return &FileList{Items: files}, nil
	}

	s.repoLock.Lock(gitClient.Root())
	defer s.repoLock.Unlock(gitClient.Root())
	commitSHA, err = checkoutRevision(gitClient, commitSHA)
	if err != nil {
		return nil, err
	}

	lsFiles, err := gitClient.LsFiles(q.Path)
	if err != nil {
		return nil, err
	}

	res := FileList{Items: lsFiles}
	err = s.cache.SetListDir(commitSHA, q.Path, res.Items)
	if err != nil {
		log.Warnf("listdir cache set error %s/%s: %v", commitSHA, q.Path, err)
	}
	return &res, nil
}
201435
func (ctrl *Controller) ServeFiles(path, filename string) error {
	if strings.Contains(path, ":") {
		return fmt.Errorf("path may only include wildcards that match the entire end of the URL (e.g. *filepath)")
	}
	LogInfo(ctrl.Context, "mount file", "name", filename, "route", fmt.Sprintf("GET %s", path))
	handler := func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		if !ContextResponse(ctx).Written() {
			return ctrl.FileHandler(path, filename)(ctx, rw, req)
		}
		return nil
	}
	ctrl.Service.Mux.Handle("GET", path, ctrl.MuxHandler("serve", handler, nil))
	return nil
}
958039
func WhiteListHostFilter(hosts ...string) HostFilter {
	hostInfos, err := addrsToHosts(hosts, 9042)
	if err != nil {
		// dont want to panic here, but rather not break the API
		panic(fmt.Errorf("unable to lookup host info from address: %v", err))
	}

	m := make(map[string]bool, len(hostInfos))
	for _, host := range hostInfos {
		m[host.ConnectAddress().String()] = true
	}

	return HostFilterFunc(func(host *HostInfo) bool {
		return m[host.ConnectAddress().String()]
	})
}
1020878
func NewServer(apiDef *raml.APIDefinition, apiDocsDir, dir string) *Server {
	return &Server{
		Title:      apiDef.Title,
		APIDef:     apiDef,
		apiDocsDir: apiDocsDir,
		Dir:        dir,
	}
}
65911
func (g *Group) FileSystem(path string, fs http.FileSystem) {
	g.server.FileSystem(g.prefix+path, fs)
}
587407
func (fs FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
	if r.Method != "GET" && r.Method != "HEAD" {
		return http.StatusMethodNotAllowed, nil
	}
	return fs.serveFile(w, r)
}
916525
func (c *Client) List(name string) ([]os.FileInfo, error) {
	return c.ListN(name, 0)
}
412298
func NewServer(apiDef *raml.APIDefinition, apiDocsDir string, targetDir string) *Server {
	resources := getServerResourcesDefs(apiDef)
	return &Server{
		apiDef:     apiDef,
		apiDocsDir: apiDocsDir,
		TargetDir:  targetDir,
		Resources:  resources,
	}
}
972184
func (r *Router) ServeFiles(path string, root http.FileSystem) {
	r.Router.ServeFiles(path, root)
}
632509
func (c *CmdSimpleFSList) createListing(dirname string, fip FileInfoPath) (Listing, error) {
	var currentListing Listing

	// permissions string
	currentListing.permissions = fip.info.Mode().String()
	if fip.info.Mode()&os.ModeSymlink == os.ModeSymlink {
		currentListing.permissions = strings.Replace(
			currentListing.permissions, "L", "l", 1)
		// Note: don't follow KBFS symlinks for now
	} else if currentListing.permissions[0] == 'D' {
		currentListing.permissions = currentListing.permissions[1:]
	} else if currentListing.permissions[0:2] == "ug" {
		currentListing.permissions =
			strings.Replace(currentListing.permissions, "ug", "-", 1)
		currentListing.permissions = fmt.Sprintf("%ss%ss%s",
			currentListing.permissions[0:3],
			currentListing.permissions[4:6],
			currentListing.permissions[7:])
	} else if currentListing.permissions[0] == 'u' {
		currentListing.permissions =
			strings.Replace(currentListing.permissions, "u", "-", 1)
		currentListing.permissions = fmt.Sprintf("%ss%s",
			currentListing.permissions[0:3],
			currentListing.permissions[4:])
	} else if currentListing.permissions[0] == 'g' {
		currentListing.permissions =
			strings.Replace(currentListing.permissions, "g", "-", 1)
		currentListing.permissions = fmt.Sprintf("%ss%s",
			currentListing.permissions[0:6],
			currentListing.permissions[7:])
	} else if currentListing.permissions[0:2] == "dt" {
		currentListing.permissions =
			strings.Replace(currentListing.permissions, "dt", "d", 1)
		currentListing.permissions = fmt.Sprintf("%st",
			currentListing.permissions[0:len(currentListing.permissions)-1])
	}

	// size
	if c.options.human {
		size := float64(fip.info.Size())

		count := 0
		for size >= 1.0 {
			size /= 1024
			count++
		}

		if count < 0 {
			count = 0
		} else if count > 0 {
			size *= 1024
			count--
		}

		var suffix string
		if count == 0 {
			suffix = "B"
		} else if count == 1 {
			suffix = "K"
		} else if count == 2 {
			suffix = "M"
		} else if count == 3 {
			suffix = "G"
		} else if count == 4 {
			suffix = "T"
		} else if count == 5 {
			suffix = "P"
		} else if count == 6 {
			suffix = "E"
		} else {
			suffix = "?"
		}

		sizeStr := ""
		if count == 0 {
			sizeB := int64(size)
			sizeStr = fmt.Sprintf("%d%s", sizeB, suffix)
		} else {
			// looks like the printf formatting automatically rounds up
			sizeStr = fmt.Sprintf("%.1f%s", size, suffix)
		}

		// drop the trailing .0 if it exists in the size
		// e.g. 14.0K -> 14K
		if len(sizeStr) > 3 &&
			sizeStr[len(sizeStr)-3:len(sizeStr)-1] == ".0" {
			sizeStr = sizeStr[0:len(sizeStr)-3] + suffix
		}

		currentListing.size = sizeStr

	} else {
		currentListing.size = fmt.Sprintf("%d", fip.info.Size())
	}

	// epochNano
	currentListing.epochNano = fip.info.ModTime().UnixNano()

	// month
	currentListing.month = fip.info.ModTime().Month().String()[0:3]

	// day
	currentListing.day = fmt.Sprintf("%02d", fip.info.ModTime().Day())

	// time
	// if older than six months, print the year
	// otherwise, print hour:minute
	epochNow := time.Now().Unix()
	var secondsInSixMonths int64 = 182 * 24 * 60 * 60
	epochSixMonthsAgo := epochNow - secondsInSixMonths
	epochModified := fip.info.ModTime().Unix()

	var timeStr string
	if epochModified <= epochSixMonthsAgo ||
		epochModified >= (epochNow+5) {
		timeStr = fmt.Sprintf("%d", fip.info.ModTime().Year())
	} else {
		timeStr = fmt.Sprintf("%02d:%02d",
			fip.info.ModTime().Hour(),
			fip.info.ModTime().Minute())
	}

	currentListing.time = timeStr

	currentListing.name = fip.path

	// character?
	if fip.info.Mode()&os.ModeCharDevice == os.ModeCharDevice {
		currentListing.isCharacter = true
	} else if fip.info.Mode()&os.ModeDevice == os.ModeDevice { // block?
		currentListing.isBlock = true
	} else if fip.info.Mode()&os.ModeNamedPipe == os.ModeNamedPipe { // pipe?
		currentListing.isPipe = true
	} else if fip.info.Mode()&os.ModeSocket == os.ModeSocket { // socket?
		currentListing.isSocket = true
	}

	return currentListing, nil
}
869501
func filelist(h FileLister, r *Request, pkt requestPacket) responsePacket {
	var err error
	lister := r.getLister()
	if lister == nil {
		return statusFromError(pkt, errors.New("unexpected dir packet"))
	}

	offset := r.lsNext()
	finfo := make([]os.FileInfo, MaxFilelist)
	n, err := lister.ListAt(finfo, offset)
	r.lsInc(int64(n))
	// ignore EOF as we only return it when there are no results
	finfo = finfo[:n] // avoid need for nil tests below

	switch r.Method {
	case "List":
		if err != nil && err != io.EOF {
			return statusFromError(pkt, err)
		}
		if err == io.EOF && n == 0 {
			return statusFromError(pkt, io.EOF)
		}
		dirname := filepath.ToSlash(path.Base(r.Filepath))
		ret := &sshFxpNamePacket{ID: pkt.id()}

		for _, fi := range finfo {
			ret.NameAttrs = append(ret.NameAttrs, sshFxpNameAttr{
				Name:     fi.Name(),
				LongName: runLs(dirname, fi),
				Attrs:    []interface{}{fi},
			})
		}
		return ret
	default:
		err = errors.Errorf("unexpected method: %s", r.Method)
		return statusFromError(pkt, err)
	}
}
1183137
func (r Network_Storage) GetFileList(folder *string, path *string) (resp []datatypes.Container_Utility_File_Entity, err error) {
	params := []interface{}{
		folder,
		path,
	}
	err = r.Session.DoRequest("SoftLayer_Network_Storage", "getFileList", params, &r.Options, &resp)
	return
}
1227627
func NewServer(store mailstore.Mailstore) *Server {
	s := &Server{
		Addr:       defaultAddress,
		mailstore:  store,
		Transcript: ioutil.Discard,
	}
	return s
}
1197836
func releaseServer(w http.ResponseWriter, r *http.Request) {
	name, ok := mux.Vars(r)["name"]
	if !ok {
		http.Error(w, "name missing in URL path", http.StatusBadRequest)
		return
	}
	mx.Lock()
	defer mx.Unlock()
	server, ok := servers[name]
	if !ok {
		http.Error(w, "no such server", http.StatusNotFound)
		return
	}
	server.Reserved = false
	if err := json.NewEncoder(w).Encode(server); err != nil {
		log.Printf("[JSON Encoding Error] %s", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
491120
func (api *API) GetSharedStorageServer(st_id string, ser_id string) (*SharedStorageServer, error) {
	result := new(SharedStorageServer)
	url := createUrl(api, sharedStoragePathSegment, st_id, "servers", ser_id)
	err := api.Client.Get(url, &result, http.StatusOK)
	if err != nil {
		return nil, err
	}
	return result, nil
}
1018516
func (s *LoadBalancerSetting) AddServer(server *LoadBalancerServer) {
	if s.Servers == nil {
		s.Servers = []*LoadBalancerServer{}
	}
	s.Servers = append(s.Servers, server)
}