Fix vet and linting errors

This commit is contained in:
Remco 2017-03-22 21:09:40 +01:00
parent 8277e88bbd
commit 01c2d426ed
3 changed files with 39 additions and 29 deletions

View file

@ -169,7 +169,7 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
// vars := mux.Vars(r) // vars := mux.Vars(r)
if acceptsHtml(r.Header) { if acceptsHTML(r.Header) {
if err := html_templates.ExecuteTemplate(w, "index.html", nil); err != nil { if err := html_templates.ExecuteTemplate(w, "index.html", nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return

View file

@ -264,7 +264,7 @@ func (s *Server) Run() {
// The file will show a preview page when opening the link in browser directly or // The file will show a preview page when opening the link in browser directly or
// from external link. If the referer url path and current path are the same it will be // from external link. If the referer url path and current path are the same it will be
// downloaded. // downloaded.
if !acceptsHtml(r.Header) { if !acceptsHTML(r.Header) {
return false return false
} }

View file

@ -44,26 +44,32 @@ func getBucket(accessKey, secretKey, bucket string) (*s3.Bucket, error) {
} }
var EUWestWithoutHTTPS = aws.Region{ var EUWestWithoutHTTPS = aws.Region{
"eu-west-1", Name: "eu-west-1",
"https://ec2.eu-west-1.amazonaws.com", EC2Endpoint: "https://ec2.eu-west-1.amazonaws.com",
"http://s3-eu-west-1.amazonaws.com", S3Endpoint: "http://s3-eu-west-1.amazonaws.com",
"", S3BucketEndpoint: "",
true, S3LocationConstraint: true,
true, S3LowercaseBucket: true,
"https://sdb.eu-west-1.amazonaws.com", SDBEndpoint: "https://sdb.eu-west-1.amazonaws.com",
"https://email.eu-west-1.amazonaws.com", SESEndpoint: "https://email.eu-west-1.amazonaws.com",
"https://sns.eu-west-1.amazonaws.com", SNSEndpoint: "https://sns.eu-west-1.amazonaws.com",
"https://sqs.eu-west-1.amazonaws.com", SQSEndpoint: "https://sqs.eu-west-1.amazonaws.com",
"https://iam.amazonaws.com", IAMEndpoint: "https://iam.amazonaws.com",
"https://elasticloadbalancing.eu-west-1.amazonaws.com", ELBEndpoint: "https://elasticloadbalancing.eu-west-1.amazonaws.com",
"https://dynamodb.eu-west-1.amazonaws.com", DynamoDBEndpoint: "https://dynamodb.eu-west-1.amazonaws.com",
aws.ServiceInfo{"https://monitoring.eu-west-1.amazonaws.com", aws.V2Signature}, CloudWatchServicepoint: aws.ServiceInfo{
"https://autoscaling.eu-west-1.amazonaws.com", Endpoint: "https://monitoring.eu-west-1.amazonaws.com",
aws.ServiceInfo{"https://rds.eu-west-1.amazonaws.com", aws.V2Signature}, Signer: aws.V2Signature,
"https://sts.amazonaws.com", },
"https://cloudformation.eu-west-1.amazonaws.com", AutoScalingEndpoint: "https://autoscaling.eu-west-1.amazonaws.com",
"https://ecs.eu-west-1.amazonaws.com", RDSEndpoint: aws.ServiceInfo{
"https://streams.dynamodb.eu-west-1.amazonaws.com", Endpoint: "https://rds.eu-west-1.amazonaws.com",
Signer: aws.V2Signature,
},
STSEndpoint: "https://sts.amazonaws.com",
CloudFormationEndpoint: "https://cloudformation.eu-west-1.amazonaws.com",
ECSEndpoint: "https://ecs.eu-west-1.amazonaws.com",
DynamoDBStreamsEndpoint: "https://streams.dynamodb.eu-west-1.amazonaws.com",
} }
conn := s3.New(auth, EUWestWithoutHTTPS) conn := s3.New(auth, EUWestWithoutHTTPS)
@ -238,11 +244,11 @@ func ipAddrFromRemoteAddr(s string) string {
return s[:idx] return s[:idx]
} }
func getIpAddress(r *http.Request) string { func getIPAddress(r *http.Request) string {
hdr := r.Header hdr := r.Header
hdrRealIp := hdr.Get("X-Real-Ip") hdrRealIP := hdr.Get("X-Real-Ip")
hdrForwardedFor := hdr.Get("X-Forwarded-For") hdrForwardedFor := hdr.Get("X-Forwarded-For")
if hdrRealIp == "" && hdrForwardedFor == "" { if hdrRealIP == "" && hdrForwardedFor == "" {
return ipAddrFromRemoteAddr(r.RemoteAddr) return ipAddrFromRemoteAddr(r.RemoteAddr)
} }
if hdrForwardedFor != "" { if hdrForwardedFor != "" {
@ -251,19 +257,23 @@ func getIpAddress(r *http.Request) string {
for i, p := range parts { for i, p := range parts {
parts[i] = strings.TrimSpace(p) parts[i] = strings.TrimSpace(p)
} }
// TODO: should return first non-local address // TODO: should return first non-local address
return parts[0] return parts[0]
} }
return hdrRealIp return hdrRealIP
} }
func encodeRFC2047(String string) string { func encodeRFC2047(s string) string {
// use mail's rfc2047 to encode any string // use mail's rfc2047 to encode any string
addr := mail.Address{String, ""} addr := mail.Address{
Name: s,
Address: "",
}
return strings.Trim(addr.String(), " <>") return strings.Trim(addr.String(), " <>")
} }
func acceptsHtml(hdr http.Header) bool { func acceptsHTML(hdr http.Header) bool {
actual := header.ParseAccept(hdr, "Accept") actual := header.ParseAccept(hdr, "Accept")
for _, s := range actual { for _, s := range actual {