...

Source file src/github.com/sassoftware/relic/server/view_directory.go

Documentation: github.com/sassoftware/relic/server

     1  //
     2  // Copyright (c) SAS Institute Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package server
    18  
    19  import (
    20  	"bytes"
    21  	"fmt"
    22  	"math/rand"
    23  	"net/http"
    24  	"net/url"
    25  	"time"
    26  )
    27  
    28  func (s *Server) serveDirectory(req *http.Request) (Response, error) {
    29  	sibs := s.Config.Server.Siblings
    30  	if len(sibs) == 0 {
    31  		u := new(url.URL)
    32  		*u = *req.URL
    33  		if req.TLS != nil {
    34  			u.Scheme = "https"
    35  		} else {
    36  			u.Scheme = "http"
    37  		}
    38  		u.Host = req.Host
    39  		sibs = []string{u.String()}
    40  	}
    41  	var buf bytes.Buffer
    42  	shuf := rand.New(rand.NewSource(time.Now().UnixNano()))
    43  	order := shuf.Perm(len(sibs))
    44  	for _, i := range order {
    45  		fmt.Fprintf(&buf, "%s\r\n", sibs[i])
    46  	}
    47  	return StringResponse(http.StatusOK, buf.String()), nil
    48  }
    49  

View as plain text