github.com/gaukas/goofys100m@v0.24.0/api/common/config.go (about) 1 // Copyright 2015 - 2019 Ka-Hing Cheung 2 // Copyright 2015 - 2017 Google Inc. All Rights Reserved. 3 // Copyright 2019 Databricks 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package common 18 19 import ( 20 "mime" 21 "net" 22 "net/http" 23 "os" 24 "strings" 25 "time" 26 ) 27 28 type FlagStorage struct { 29 // File system 30 MountOptions map[string]string 31 MountPoint string 32 MountPointArg string 33 MountPointCreated string 34 35 Cache []string 36 DirMode os.FileMode 37 FileMode os.FileMode 38 Uid uint32 39 Gid uint32 40 41 // Common Backend Config 42 UseContentType bool 43 Endpoint string 44 45 Backend interface{} 46 47 // Tuning 48 Cheap bool 49 ExplicitDir bool 50 StatCacheTTL time.Duration 51 TypeCacheTTL time.Duration 52 HTTPTimeout time.Duration 53 54 // Debugging 55 DebugFuse bool 56 DebugS3 bool 57 Foreground bool 58 } 59 60 func (flags *FlagStorage) GetMimeType(fileName string) (retMime *string) { 61 if flags.UseContentType { 62 dotPosition := strings.LastIndex(fileName, ".") 63 if dotPosition == -1 { 64 return nil 65 } 66 mimeType := mime.TypeByExtension(fileName[dotPosition:]) 67 if mimeType == "" { 68 return nil 69 } 70 semicolonPosition := strings.LastIndex(mimeType, ";") 71 if semicolonPosition == -1 { 72 return &mimeType 73 } 74 s := mimeType[:semicolonPosition] 75 retMime = &s 76 } 77 78 return 79 } 80 81 func (flags *FlagStorage) Cleanup() { 82 if flags.MountPointCreated != "" && flags.MountPointCreated != flags.MountPointArg { 83 err := os.Remove(flags.MountPointCreated) 84 if err != nil { 85 log.Errorf("rmdir %v = %v", flags.MountPointCreated, err) 86 } 87 } 88 } 89 90 var defaultHTTPTransport = http.Transport{ 91 Proxy: http.ProxyFromEnvironment, 92 DialContext: (&net.Dialer{ 93 Timeout: 30 * time.Second, 94 KeepAlive: 30 * time.Second, 95 DualStack: true, 96 }).DialContext, 97 MaxIdleConns: 1000, 98 MaxIdleConnsPerHost: 1000, 99 IdleConnTimeout: 90 * time.Second, 100 TLSHandshakeTimeout: 10 * time.Second, 101 ExpectContinueTimeout: 10 * time.Second, 102 } 103 104 func GetHTTPTransport() *http.Transport { 105 return &defaultHTTPTransport 106 }