├── .gitignore ├── .travis.yml ├── scheduler ├── warehouse.go └── warehouse_test.go ├── downloader ├── http_test.go └── http.go ├── setting ├── browser.go └── setting.go ├── useragent ├── cache │ ├── rawgithub_test.go │ ├── file_test.go │ ├── rawgithub.go │ └── file.go └── warehouse.go ├── spiders └── browser.go ├── browser.go ├── browser_test.go ├── b.go ├── README_ZH.md ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | 4 | *.o 5 | *.a 6 | *.so 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.8.x 4 | - 1.9.x 5 | - 1.10.x 6 | - master 7 | 8 | script: 9 | - go test -v ./... 10 | -------------------------------------------------------------------------------- /scheduler/warehouse.go: -------------------------------------------------------------------------------- 1 | package scheduler 2 | 3 | var URLs = []string{} 4 | 5 | func PopUrl() string { 6 | length := len(URLs) 7 | if length < 1 { 8 | return "" 9 | } 10 | 11 | url := URLs[length-1] 12 | URLs = URLs[:length-1] 13 | return url 14 | } 15 | 16 | func AppendUrl(url string) { 17 | URLs = append(URLs, url) 18 | } 19 | 20 | func CountUrl() int { 21 | return len(URLs) 22 | } 23 | -------------------------------------------------------------------------------- /downloader/http_test.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "github.com/EDDYCJY/fake-useragent/setting" 5 | "testing" 6 | ) 7 | 8 | func TestDownload_Get(t *testing.T) { 9 | downloader := Download{ 10 | Delay: setting.HTTP_DELAY, 11 | Timeout: setting.HTTP_TIMEOUT, 12 | } 13 | 14 | _, err := downloader.Get("https://developers.whatismybrowser.com") 15 | if err != nil { 16 | t.Errorf("downloader.Get err: %v", err) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /scheduler/warehouse_test.go: -------------------------------------------------------------------------------- 1 | package scheduler 2 | 3 | import "testing" 4 | 5 | func TestAppendUrl(t *testing.T) { 6 | AppendUrl("https://www.google.com/") 7 | AppendUrl("https://golang.org/") 8 | } 9 | 10 | func TestPopUrl(t *testing.T) { 11 | if url := PopUrl(); url == "" { 12 | t.Errorf("Expected value, but empty") 13 | } 14 | } 15 | 16 | func TestCountUrl(t *testing.T) { 17 | if count := CountUrl(); count != 1 { 18 | t.Errorf("Expected 1, got %d", count) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /setting/browser.go: -------------------------------------------------------------------------------- 1 | package setting 2 | 3 | const ( 4 | CHROME = "chrome" 5 | INTERNET_EXPLORER = "internet-explorer" 6 | FIREFOX = "firefox" 7 | SAFARI = "safari" 8 | 9 | ANDROID = "android" 10 | MAC_OS_X = "mac-os-x" 11 | IOS = "ios" 12 | LINUX = "linux" 13 | 14 | IPHONE = "iphone" 15 | IPAD = "ipad" 16 | 17 | COMPUTER = "computer" 18 | MOBILE = "mobile" 19 | ) 20 | 21 | var ( 22 | BrowserUserAgentMaps = map[string][]string{ 23 | "software_name": { 24 | CHROME, 25 | INTERNET_EXPLORER, 26 | FIREFOX, 27 | SAFARI, 28 | }, 29 | "operating_system_name": { 30 | ANDROID, 31 | MAC_OS_X, 32 | IOS, 33 | LINUX, 34 | }, 35 | "operating_platform": { 36 | IPHONE, 37 | IPAD, 38 | }, 39 | "hardware_type_specific" : { 40 | COMPUTER, 41 | MOBILE, 42 | }, 43 | } 44 | ) 45 | -------------------------------------------------------------------------------- /useragent/cache/rawgithub_test.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "testing" 5 | "fmt" 6 | "github.com/EDDYCJY/fake-useragent/setting" 7 | "net/http" 8 | ) 9 | 10 | var r = NewRawCache(setting.CACHE_URL, fmt.Sprintf(setting.TEMP_FILE_NAME, setting.CACHE_VERSION)) 11 | var rawResp *http.Response 12 | 13 | func TestRaw_Get(t *testing.T) { 14 | resp, exist, err := r.Get() 15 | if err != nil { 16 | t.Errorf("r.Get err: %v", err) 17 | } 18 | if exist == false { 19 | t.Errorf("r.Get not exist") 20 | } 21 | 22 | rawResp = resp 23 | } 24 | 25 | func TestRaw_IsExist(t *testing.T) { 26 | exist := r.IsExist(rawResp) 27 | if exist == false { 28 | t.Errorf("r.IsExist not exist") 29 | } 30 | } 31 | 32 | func TestRaw_Read(t *testing.T) { 33 | defer rawResp.Body.Close() 34 | body ,err := r.Read(rawResp.Body) 35 | if err != nil { 36 | t.Errorf("r.Get err: %v", err) 37 | } 38 | if len(body) == 0 { 39 | t.Errorf("r.Read len is zero") 40 | } 41 | } -------------------------------------------------------------------------------- /downloader/http.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | type Download struct { 10 | Delay time.Duration 11 | Timeout time.Duration 12 | } 13 | 14 | func (d *Download) Get(url string) (* http.Response, error) { 15 | time.Sleep(d.Delay) 16 | 17 | client := &http.Client{ 18 | Transport: &http.Transport{ 19 | Proxy: http.ProxyFromEnvironment, 20 | DialContext: (&net.Dialer{ 21 | Timeout: d.Timeout, 22 | KeepAlive: 30 * time.Second, 23 | DualStack: true, 24 | }).DialContext, 25 | MaxIdleConns: 100, 26 | IdleConnTimeout: 90 * time.Second, 27 | TLSHandshakeTimeout: 10 * time.Second, 28 | ExpectContinueTimeout: 1 * time.Second, 29 | }, 30 | } 31 | 32 | req, err := http.NewRequest("GET", url, nil) 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | resp, err := client.Do(req) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | return resp, nil 43 | } 44 | -------------------------------------------------------------------------------- /useragent/cache/file_test.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/EDDYCJY/fake-useragent/setting" 8 | ) 9 | 10 | var f = NewFileCache(GetTempDir(), fmt.Sprintf(setting.TEMP_FILE_TEST_NAME, setting.VERSION)) 11 | 12 | func TestFile_Write(t *testing.T) { 13 | err := f.Write([]byte("test")) 14 | if err != nil { 15 | t.Errorf("f.Write err: %v", err) 16 | } 17 | } 18 | 19 | func TestFile_Read(t *testing.T) { 20 | value, err := f.Read() 21 | if err != nil { 22 | t.Errorf("f.Read err: %v", err) 23 | } 24 | 25 | str := string(value) 26 | if str != "test" { 27 | t.Errorf("Expected 'test', got %s", str) 28 | } 29 | } 30 | 31 | func TestFile_Remove(t *testing.T) { 32 | err := f.Remove() 33 | if err != nil { 34 | t.Errorf("f.Remove err: %v", err) 35 | } 36 | } 37 | 38 | func TestFile_IsExist(t *testing.T) { 39 | exist, err := f.IsExist() 40 | if exist == true { 41 | t.Errorf("Expected false, got true") 42 | } 43 | if err != nil { 44 | t.Errorf("f.IsExist err: %v", err) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /setting/setting.go: -------------------------------------------------------------------------------- 1 | package setting 2 | 3 | import "time" 4 | 5 | const ( 6 | VERSION = "0.2.0" 7 | 8 | BROWSER_URL = "https://developers.whatismybrowser.com/useragents/explore/%s/%s/%d" 9 | BROWSER_MAX_PAGE = 5 10 | BROWSER_ALLOW_MAX_PAGE = 8 11 | 12 | CACHE_VERSION = "0.2.0" 13 | CACHE_URL = "https://raw.githubusercontent.com/EDDYCJY/fake-useragent/v0.2.0/static/" 14 | 15 | HTTP_TIMEOUT = 5 * time.Second 16 | HTTP_DELAY = 100 * time.Millisecond 17 | HTTP_ALLOW_MIN_DELAY = 100 * time.Millisecond 18 | 19 | TEMP_FILE_NAME = "fake_useragent_%s.json" 20 | TEMP_FILE_TEST_NAME = "fake_useragent_test_%s.json" 21 | ) 22 | 23 | func GetMaxPage(maxPage int) int { 24 | if maxPage > BROWSER_ALLOW_MAX_PAGE || maxPage == 0 { 25 | maxPage = BROWSER_MAX_PAGE 26 | } 27 | 28 | return maxPage 29 | } 30 | 31 | func GetDelay(delay time.Duration) time.Duration { 32 | if delay < HTTP_ALLOW_MIN_DELAY { 33 | delay = HTTP_ALLOW_MIN_DELAY 34 | } 35 | 36 | return delay 37 | } 38 | 39 | func GetTimeout(timeout time.Duration) time.Duration { 40 | if timeout == 0 { 41 | timeout = HTTP_TIMEOUT 42 | } 43 | 44 | return timeout 45 | } 46 | -------------------------------------------------------------------------------- /useragent/cache/rawgithub.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "io/ioutil" 5 | "github.com/EDDYCJY/fake-useragent/downloader" 6 | "github.com/EDDYCJY/fake-useragent/setting" 7 | "time" 8 | "io" 9 | "net/http" 10 | ) 11 | 12 | type raw struct { 13 | Dir string 14 | Name string 15 | CompletePath string 16 | } 17 | 18 | func NewRawCache(dir string, name string) *raw { 19 | return &raw{ 20 | Dir: dir, 21 | Name: name, 22 | CompletePath: dir + name, 23 | } 24 | } 25 | 26 | func (f *raw) Get() (*http.Response, bool, error) { 27 | downloader := downloader.Download{ 28 | Delay: setting.GetDelay(time.Duration(0)), 29 | Timeout: setting.GetTimeout(time.Duration(0)), 30 | } 31 | 32 | resp, err := downloader.Get(f.CompletePath) 33 | if err != nil { 34 | return nil, false, err 35 | } 36 | 37 | return resp, f.IsExist(resp), nil 38 | } 39 | 40 | func (f *raw) Read(body io.ReadCloser) ([]byte, error) { 41 | return ioutil.ReadAll(body) 42 | } 43 | 44 | func (f *raw) IsExist(resp *http.Response) bool { 45 | if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotModified { 46 | return true 47 | } 48 | 49 | return false 50 | } -------------------------------------------------------------------------------- /useragent/warehouse.go: -------------------------------------------------------------------------------- 1 | package useragent 2 | 3 | import ( 4 | "math/rand" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | type useragent struct { 10 | data map[string][]string 11 | lock sync.Mutex 12 | } 13 | 14 | var ( 15 | UA = useragent{data: make(map[string][]string)} 16 | r = rand.New(rand.NewSource(time.Now().UnixNano())) 17 | ) 18 | 19 | func (u *useragent) Get(key string) []string { 20 | return u.data[key] 21 | } 22 | 23 | func (u *useragent) GetAll() map[string][]string { 24 | return u.data 25 | } 26 | 27 | func (u *useragent) GetRandom(key string) string { 28 | browser := u.Get(key) 29 | len := len(browser) 30 | if len < 1 { 31 | return "" 32 | } 33 | 34 | n := r.Intn(len) 35 | return browser[n] 36 | } 37 | 38 | func (u *useragent) GetAllRandom() string { 39 | browsers := u.GetAll() 40 | datas := []string{} 41 | for _, uas := range browsers { 42 | datas = append(datas, uas...) 43 | } 44 | 45 | len := len(datas) 46 | if len < 1 { 47 | return "" 48 | } 49 | 50 | n := r.Intn(len) 51 | return datas[n] 52 | } 53 | 54 | func (u *useragent) Set(key, value string) { 55 | u.lock.Lock() 56 | defer u.lock.Unlock() 57 | u.data[key] = append(u.data[key], value) 58 | } 59 | 60 | func (u *useragent) SetData(data map[string][]string) { 61 | u.data = data 62 | } 63 | -------------------------------------------------------------------------------- /useragent/cache/file.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "strings" 7 | "encoding/json" 8 | ) 9 | 10 | type File struct { 11 | Dir string 12 | Name string 13 | CompletePath string 14 | } 15 | 16 | func NewFileCache(dir string, name string) *File { 17 | return &File{ 18 | Dir: dir, 19 | Name: name, 20 | CompletePath: dir + name, 21 | } 22 | } 23 | 24 | func (f *File) Read() ([]byte, error) { 25 | return ioutil.ReadFile(f.CompletePath) 26 | } 27 | 28 | func (f *File) Write(data []byte) error { 29 | return ioutil.WriteFile(f.CompletePath, data, 0644) 30 | } 31 | 32 | func (f *File) WriteJson(v interface{}) error { 33 | uasJson, err := json.Marshal(v) 34 | if err != nil { 35 | return err 36 | } 37 | 38 | return f.Write(uasJson) 39 | } 40 | 41 | func (f *File) Remove() error { 42 | err := os.Remove(f.CompletePath) 43 | if err != nil { 44 | return err 45 | } 46 | 47 | return nil 48 | } 49 | 50 | func (f *File) IsExist() (bool, error) { 51 | _, err := os.Stat(f.CompletePath) 52 | if err == nil { 53 | return true, nil 54 | } 55 | 56 | if os.IsNotExist(err) { 57 | return false, nil 58 | } 59 | 60 | return false, err 61 | } 62 | 63 | func GetTempDir() string { 64 | tempDir := os.TempDir() 65 | if exist := strings.HasSuffix(tempDir, "/"); exist == false { 66 | tempDir = tempDir + "/" 67 | } 68 | 69 | return tempDir 70 | } 71 | -------------------------------------------------------------------------------- /spiders/browser.go: -------------------------------------------------------------------------------- 1 | package spiders 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/PuerkitoBio/goquery" 9 | "github.com/nozzle/throttler" 10 | 11 | "github.com/EDDYCJY/fake-useragent/downloader" 12 | "github.com/EDDYCJY/fake-useragent/scheduler" 13 | "github.com/EDDYCJY/fake-useragent/setting" 14 | "github.com/EDDYCJY/fake-useragent/useragent" 15 | ) 16 | 17 | type Spider struct { 18 | Attribute 19 | FullUrl string 20 | } 21 | 22 | type Attribute struct { 23 | Tag string 24 | Category string 25 | Page int 26 | } 27 | 28 | var urlAttributeResults = make(map[string]Attribute) 29 | 30 | func NewBrowserSpider() *Spider { 31 | return &Spider{} 32 | } 33 | 34 | func (a *Attribute) GetSpider() *Spider { 35 | return &Spider{ 36 | Attribute: Attribute{ 37 | Tag: a.Tag, 38 | Category: a.Category, 39 | Page: a.Page, 40 | }, 41 | FullUrl: fmt.Sprintf(setting.BROWSER_URL, a.Tag, a.Category, a.Page), 42 | } 43 | } 44 | 45 | func (s *Spider) AppendBrowser(maxPage int) { 46 | for tag, categorys := range setting.BrowserUserAgentMaps { 47 | for _, category := range categorys { 48 | for page := 1; page <= maxPage; page++ { 49 | attribute := Attribute{Tag: tag, Category: category, Page: page} 50 | urlAttributeResults[attribute.GetSpider().FullUrl] = attribute 51 | scheduler.AppendUrl(attribute.GetSpider().FullUrl) 52 | } 53 | } 54 | } 55 | } 56 | 57 | func (s *Spider) StartBrowser(delay time.Duration, timeout time.Duration) { 58 | count := scheduler.CountUrl() 59 | th := throttler.New(5, count) 60 | for i := 0; i <= count; i++ { 61 | go func() { 62 | var ( 63 | resp *http.Response 64 | doc *goquery.Document 65 | err error 66 | ) 67 | defer th.Done(err) 68 | 69 | if url := scheduler.PopUrl(); url != "" { 70 | downloader := downloader.Download{Delay: delay, Timeout: timeout} 71 | resp, err = downloader.Get(url) 72 | if err != nil { 73 | return 74 | } 75 | defer resp.Body.Close() 76 | 77 | doc, err = goquery.NewDocumentFromReader(resp.Body) 78 | if err != nil { 79 | return 80 | } 81 | 82 | doc.Find("td.useragent a").Each(func(i int, selection *goquery.Selection) { 83 | if value := selection.Text(); value != "" { 84 | useragent.UA.Set(urlAttributeResults[url].Category, value) 85 | } 86 | }) 87 | } 88 | }() 89 | 90 | th.Throttle() 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /browser.go: -------------------------------------------------------------------------------- 1 | package browser 2 | 3 | import ( 4 | "github.com/EDDYCJY/fake-useragent/setting" 5 | "github.com/EDDYCJY/fake-useragent/useragent" 6 | ) 7 | 8 | func Random() string { 9 | return defaultBrowser.Random() 10 | } 11 | 12 | func Chrome() string { 13 | return defaultBrowser.Chrome() 14 | } 15 | 16 | func InternetExplorer() string { 17 | return defaultBrowser.InternetExplorer() 18 | } 19 | 20 | func Firefox() string { 21 | return defaultBrowser.Firefox() 22 | } 23 | 24 | func Safari() string { 25 | return defaultBrowser.Safari() 26 | } 27 | 28 | func Android() string { 29 | return defaultBrowser.Android() 30 | } 31 | 32 | func MacOSX() string { 33 | return defaultBrowser.MacOSX() 34 | } 35 | 36 | func IOS() string { 37 | return defaultBrowser.IOS() 38 | } 39 | 40 | func Linux() string { 41 | return defaultBrowser.Linux() 42 | } 43 | 44 | func IPhone() string { 45 | return defaultBrowser.IPhone() 46 | } 47 | 48 | func IPad() string { 49 | return defaultBrowser.IPad() 50 | } 51 | 52 | func Computer() string { 53 | return defaultBrowser.Computer() 54 | } 55 | 56 | func Mobile() string { 57 | return defaultBrowser.Mobile() 58 | } 59 | 60 | func (b *browser) Random() string { 61 | return useragent.UA.GetAllRandom() 62 | } 63 | 64 | func (b *browser) Chrome() string { 65 | return useragent.UA.GetRandom(setting.CHROME) 66 | } 67 | 68 | func (b *browser) InternetExplorer() string { 69 | return useragent.UA.GetRandom(setting.INTERNET_EXPLORER) 70 | } 71 | 72 | func (b *browser) Firefox() string { 73 | return useragent.UA.GetRandom(setting.FIREFOX) 74 | } 75 | 76 | func (b *browser) Safari() string { 77 | return useragent.UA.GetRandom(setting.SAFARI) 78 | } 79 | 80 | func (b *browser) Android() string { 81 | return useragent.UA.GetRandom(setting.ANDROID) 82 | } 83 | 84 | func (b *browser) MacOSX() string { 85 | return useragent.UA.GetRandom(setting.MAC_OS_X) 86 | } 87 | 88 | func (b *browser) IOS() string { 89 | return useragent.UA.GetRandom(setting.IOS) 90 | } 91 | 92 | func (b *browser) Linux() string { 93 | return useragent.UA.GetRandom(setting.LINUX) 94 | } 95 | 96 | func (b *browser) IPhone() string { 97 | return useragent.UA.GetRandom(setting.IPHONE) 98 | } 99 | 100 | func (b *browser) IPad() string { 101 | return useragent.UA.GetRandom(setting.IPAD) 102 | } 103 | 104 | func (b *browser) Computer() string { 105 | return useragent.UA.GetRandom(setting.COMPUTER) 106 | } 107 | 108 | func (b *browser) Mobile() string { 109 | return useragent.UA.GetRandom(setting.MOBILE) 110 | } -------------------------------------------------------------------------------- /browser_test.go: -------------------------------------------------------------------------------- 1 | package browser 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestRandom(t *testing.T) { 9 | if Random() == "" { 10 | t.Error("browser.Random is empty") 11 | } 12 | } 13 | 14 | func TestChrome(t *testing.T) { 15 | if Chrome() == "" { 16 | t.Error("browser.Chrome is empty") 17 | } 18 | } 19 | 20 | func TestInternetExplorer(t *testing.T) { 21 | if InternetExplorer() == "" { 22 | t.Error("browser.InternetExplorer is empty") 23 | } 24 | } 25 | 26 | func TestFirefox(t *testing.T) { 27 | if Firefox() == "" { 28 | t.Error("browser.Firefox is empty") 29 | } 30 | } 31 | 32 | func TestSafari(t *testing.T) { 33 | if Safari() == "" { 34 | t.Error("browser.Safari is empty") 35 | } 36 | } 37 | 38 | func TestAndroid(t *testing.T) { 39 | if Android() == "" { 40 | t.Error("browser.Android is empty") 41 | } 42 | } 43 | 44 | func TestMacOSX(t *testing.T) { 45 | if MacOSX() == "" { 46 | t.Error("browser.MacOSX is empty") 47 | } 48 | } 49 | 50 | func TestIOS(t *testing.T) { 51 | if IOS() == "" { 52 | t.Error("browser.IOS is empty") 53 | } 54 | } 55 | 56 | func TestLinux(t *testing.T) { 57 | if Linux() == "" { 58 | t.Error("browser.IOS is empty") 59 | } 60 | } 61 | 62 | func TestIPhone(t *testing.T) { 63 | if IPhone() == "" { 64 | t.Error("browser.IPhone is empty") 65 | } 66 | } 67 | 68 | func TestIPad(t *testing.T) { 69 | if IPad() == "" { 70 | t.Error("browser.IPad is empty") 71 | } 72 | } 73 | 74 | func TestComputer(t *testing.T) { 75 | if Computer() == "" { 76 | t.Error("browser.Computer is empty") 77 | } 78 | } 79 | 80 | func TestMobile(t *testing.T) { 81 | if Mobile() == "" { 82 | t.Error("browser.Mobile is empty") 83 | } 84 | } 85 | 86 | func TestBrowser_Random(t *testing.T) { 87 | b := NewBrowser(Client{ 88 | MaxPage: 1, 89 | Delay: 200 * time.Millisecond, 90 | Timeout: 10 * time.Second, 91 | }, Cache{ 92 | UpdateFile: true, 93 | }) 94 | 95 | if b.Random() == "" { 96 | t.Error("NewBrowser.Random is empty") 97 | } 98 | } 99 | 100 | func TestBrowser_Chrome(t *testing.T) { 101 | b := NewBrowser(Client{ 102 | MaxPage: 1, 103 | Delay: 250 * time.Millisecond, 104 | Timeout: 20 * time.Second, 105 | }, Cache{}) 106 | 107 | if b.Chrome() == "" { 108 | t.Error("NewBrowser.Chrome is empty") 109 | } 110 | } 111 | 112 | func TestBrowser_IOS(t *testing.T) { 113 | b := NewBrowser(Client{ 114 | MaxPage: 1, 115 | Delay: 350 * time.Millisecond, 116 | Timeout: 20 * time.Second, 117 | }, Cache{ 118 | UpdateFile: true, 119 | }) 120 | 121 | if b.IOS() == "" { 122 | t.Error("NewBrowser.IOS is empty") 123 | } 124 | } -------------------------------------------------------------------------------- /b.go: -------------------------------------------------------------------------------- 1 | package browser 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "time" 8 | 9 | "github.com/EDDYCJY/fake-useragent/setting" 10 | "github.com/EDDYCJY/fake-useragent/spiders" 11 | "github.com/EDDYCJY/fake-useragent/useragent" 12 | "github.com/EDDYCJY/fake-useragent/useragent/cache" 13 | ) 14 | 15 | type browser struct { 16 | Client 17 | Cache 18 | } 19 | 20 | type Client struct { 21 | MaxPage int 22 | Delay time.Duration 23 | Timeout time.Duration 24 | } 25 | 26 | type Cache struct { 27 | UpdateFile bool 28 | } 29 | 30 | var defaultBrowser = NewBrowser(Client{ 31 | MaxPage: setting.BROWSER_MAX_PAGE, 32 | Delay: setting.HTTP_DELAY, 33 | Timeout: setting.HTTP_TIMEOUT, 34 | }, Cache{}) 35 | 36 | func NewBrowser(client Client, cache Cache) *browser { 37 | maxPage := setting.GetMaxPage(client.MaxPage) 38 | delay := setting.GetDelay(client.Delay) 39 | timeout := setting.GetTimeout(client.Timeout) 40 | 41 | b := browser{ 42 | Client: Client{ 43 | MaxPage: maxPage, 44 | Delay: delay, 45 | Timeout: timeout, 46 | }, 47 | Cache: Cache{ 48 | UpdateFile: cache.UpdateFile, 49 | }, 50 | } 51 | return b.load() 52 | } 53 | 54 | func (b *browser) load() *browser { 55 | fileCache := cache.NewFileCache(cache.GetTempDir(), fmt.Sprintf(setting.TEMP_FILE_NAME, setting.VERSION)) 56 | fileExist, err := fileCache.IsExist() 57 | if err != nil { 58 | log.Fatalf("fileCache.IsExist err: %v", err) 59 | } 60 | 61 | // handle cache. 62 | if b.UpdateFile == false { 63 | var ( 64 | isCache bool 65 | cacheContent []byte 66 | m map[string][]string 67 | ) 68 | 69 | if fileExist == true { 70 | cacheContent, err = fileCache.Read() 71 | if err != nil { 72 | log.Fatalf("fileCache.Read err: %v", err) 73 | } 74 | isCache = true 75 | } else { 76 | rawCache := cache.NewRawCache(setting.CACHE_URL, fmt.Sprintf(setting.TEMP_FILE_NAME, setting.CACHE_VERSION)) 77 | rawResp, rawExist, err := rawCache.Get() 78 | if err == nil && rawExist == true { 79 | defer rawResp.Body.Close() 80 | rawRead, err := rawCache.Read(rawResp.Body) 81 | if err == nil && len(rawRead) > 0 { 82 | cacheContent = rawRead 83 | isCache = true 84 | } 85 | } 86 | } 87 | 88 | if isCache == true { 89 | json.Unmarshal(cacheContent, &m) 90 | useragent.UA.SetData(m) 91 | if fileExist == false { 92 | fileCache.WriteJson(useragent.UA.GetAll()) 93 | } 94 | return b 95 | } 96 | } 97 | 98 | // handle origin. 99 | s := spiders.NewBrowserSpider() 100 | s.AppendBrowser(b.MaxPage) 101 | s.StartBrowser(b.Delay, b.Timeout) 102 | if fileExist == true && b.UpdateFile == true { 103 | err := fileCache.Remove() 104 | if err != nil { 105 | log.Fatalf("fileCache.Remove err: %v", err) 106 | } 107 | } 108 | 109 | fileCache.WriteJson(useragent.UA.GetAll()) 110 | return b 111 | } 112 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # Fake Useragent ![image](https://api.travis-ci.org/EDDYCJY/fake-useragent.svg?branch=master) 2 | 3 | 各种各样的随机浏览器头 😆 4 | 5 | ## 支持 6 | 7 | - All User-Agent Random 8 | - Chrome 9 | - InternetExplorer (IE) 10 | - Firefox 11 | - Safari 12 | - Android 13 | - MacOSX 14 | - IOS 15 | - Linux 16 | - IPhone 17 | - IPad 18 | - Computer 19 | - Mobile 20 | 21 | ## 安装 22 | 23 | ``` 24 | $ go get github.com/EDDYCJY/fake-useragent 25 | ``` 26 | 27 | ## 用法 28 | 29 | ``` go 30 | package main 31 | 32 | import ( 33 | "log" 34 | 35 | "github.com/EDDYCJY/fake-useragent" 36 | ) 37 | 38 | func main() { 39 | // 推荐使用 40 | random := browser.Random() 41 | log.Printf("Random: %s", random) 42 | 43 | chrome := browser.Chrome() 44 | log.Printf("Chrome: %s", chrome) 45 | 46 | internetExplorer := browser.InternetExplorer() 47 | log.Printf("IE: %s", internetExplorer) 48 | 49 | firefox := browser.Firefox() 50 | log.Printf("Firefox: %s", firefox) 51 | 52 | safari := browser.Safari() 53 | log.Printf("Safari: %s", safari) 54 | 55 | android := browser.Android() 56 | log.Printf("Android: %s", android) 57 | 58 | macOSX := browser.MacOSX() 59 | log.Printf("MacOSX: %s", macOSX) 60 | 61 | ios := browser.IOS() 62 | log.Printf("IOS: %s", ios) 63 | 64 | linux := browser.Linux() 65 | log.Printf("Linux: %s", linux) 66 | 67 | iphone := browser.IPhone() 68 | log.Printf("IPhone: %s", iphone) 69 | 70 | ipad := browser.IPad() 71 | log.Printf("IPad: %s", ipad) 72 | 73 | computer := browser.Computer() 74 | log.Printf("Computer: %s", computer) 75 | 76 | mobile := browser.Mobile() 77 | log.Printf("Mobile: %s", mobile) 78 | } 79 | ``` 80 | 81 | ### 定制 82 | 83 | 你可以调整抓取页面的最大数量、时间间隔以及最大超时时间。 如果不填写,则为默认值。 84 | 85 | ``` go 86 | client := browser.Client{ 87 | MaxPage: 3, 88 | Delay: 200 * time.Millisecond, 89 | Timeout: 10 * time.Second, 90 | } 91 | cache := browser.Cache{} 92 | b := browser.NewBrowser(client, cache) 93 | 94 | random := b.Random() 95 | ``` 96 | 97 | 更新浏览器临时文件缓存(重新到源获取最新数据) 98 | 99 | ``` go 100 | client := browser.Client{} 101 | cache := browser.Cache{ 102 | UpdateFile: true, 103 | } 104 | b := browser.NewBrowser(client, cache) 105 | ``` 106 | 107 | 在最后,我是建议常规用法就好,默认参数能够满足日常需求 108 | 109 | ## 输出 110 | 111 | ``` sh 112 | Random: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 113 | 114 | Chrome: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 115 | 116 | IE: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) 117 | 118 | Firefox: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0 119 | 120 | Safari: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D60 Safari/604.1 121 | 122 | Android: Mozilla/5.0 (Linux; Android 6.0; MYA-L22 Build/HUAWEIMYA-L22) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36 123 | 124 | MacOSX: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14 125 | 126 | IOS: Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B72 Safari/602.1 127 | 128 | Linux: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0 129 | 130 | IPhone: Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1 131 | 132 | IPad: Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3 133 | 134 | Computer: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0 135 | 136 | Mobile: Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36 137 | ``` 138 | 139 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fake Useragent ![image](https://api.travis-ci.org/EDDYCJY/fake-useragent.svg?branch=master) 2 | 3 | A wide variety of random useragents 4 | 5 | [简体中文](https://github.com/EDDYCJY/fake-useragent/blob/master/README_ZH.md) 6 | 7 | ## Support 8 | 9 | - All User-Agent Random 10 | - Chrome 11 | - InternetExplorer (IE) 12 | - Firefox 13 | - Safari 14 | - Android 15 | - MacOSX 16 | - IOS 17 | - Linux 18 | - IPhone 19 | - IPad 20 | - Computer 21 | - Mobile 22 | 23 | ## Installation 24 | 25 | ``` 26 | $ go get github.com/EDDYCJY/fake-useragent 27 | ``` 28 | 29 | ## Usage 30 | 31 | ``` go 32 | package main 33 | 34 | import ( 35 | "log" 36 | 37 | "github.com/EDDYCJY/fake-useragent" 38 | ) 39 | 40 | func main() { 41 | // recommend to use 42 | random := browser.Random() 43 | log.Printf("Random: %s", random) 44 | 45 | chrome := browser.Chrome() 46 | log.Printf("Chrome: %s", chrome) 47 | 48 | internetExplorer := browser.InternetExplorer() 49 | log.Printf("IE: %s", internetExplorer) 50 | 51 | firefox := browser.Firefox() 52 | log.Printf("Firefox: %s", firefox) 53 | 54 | safari := browser.Safari() 55 | log.Printf("Safari: %s", safari) 56 | 57 | android := browser.Android() 58 | log.Printf("Android: %s", android) 59 | 60 | macOSX := browser.MacOSX() 61 | log.Printf("MacOSX: %s", macOSX) 62 | 63 | ios := browser.IOS() 64 | log.Printf("IOS: %s", ios) 65 | 66 | linux := browser.Linux() 67 | log.Printf("Linux: %s", linux) 68 | 69 | iphone := browser.IPhone() 70 | log.Printf("IPhone: %s", iphone) 71 | 72 | ipad := browser.IPad() 73 | log.Printf("IPad: %s", ipad) 74 | 75 | computer := browser.Computer() 76 | log.Printf("Computer: %s", computer) 77 | 78 | mobile := browser.Mobile() 79 | log.Printf("Mobile: %s", mobile) 80 | } 81 | ``` 82 | 83 | ### Customize 84 | 85 | You can adjust the maximum number of crawl pages and time intervals, maximum timeouts. If not, it is the default. 86 | 87 | ``` go 88 | client := browser.Client{ 89 | MaxPage: 3, 90 | Delay: 200 * time.Millisecond, 91 | Timeout: 10 * time.Second, 92 | } 93 | cache := browser.Cache{} 94 | b := browser.NewBrowser(client, cache) 95 | 96 | random := b.Random() 97 | ``` 98 | 99 | Update the browser temporary file cache (re-get the source to get the latest data). 100 | 101 | ``` go 102 | client := browser.Client{} 103 | cache := browser.Cache{ 104 | UpdateFile: true, 105 | } 106 | b := browser.NewBrowser(client, cache) 107 | ``` 108 | 109 | ## Output 110 | 111 | ``` sh 112 | Random: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 113 | 114 | Chrome: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 115 | 116 | IE: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) 117 | 118 | Firefox: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0 119 | 120 | Safari: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D60 Safari/604.1 121 | 122 | Android: Mozilla/5.0 (Linux; Android 6.0; MYA-L22 Build/HUAWEIMYA-L22) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36 123 | 124 | MacOSX: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14 125 | 126 | IOS: Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B72 Safari/602.1 127 | 128 | Linux: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0 129 | 130 | IPhone: Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1 131 | 132 | IPad: Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3 133 | 134 | Computer: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0 135 | 136 | Mobile: Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36 137 | ``` 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------