Documentation ¶
Overview ¶
Package helper handles common functions for the waybackk application in Golang.
Index ¶
- func Byte2String(b []byte) string
- func CheckContext(ctx context.Context, t leaktest.ErrorReporter)
- func CheckTest(t leaktest.ErrorReporter)
- func CheckTimeout(t leaktest.ErrorReporter, d time.Duration)
- func Exists(name string) bool
- func FileName(link, contentType string) string
- func FileSize(filepath string) int64
- func FindChromeExecPath() string
- func HasStdin() bool
- func IsDir(path string) bool
- func IsURL(str string) bool
- func MatchURL(text string) []string
- func MatchURLFallback(text string) []string
- func MockServer() (*http.Client, *http.ServeMux, *httptest.Server)
- func MoveFile(src, dst string) error
- func NotFound(uri string) bool
- func RandString(length int, letter string) string
- func ReadStdin() (stdin []string)
- func RealURI(u *url.URL) *url.URL
- func RetryRemoveAll(path string, retries int) error
- func SetField(v interface{}, name string, value string) error
- func String2Byte(s string) (b []byte)
- func TinyURL(link string) string
- func UTF8Encoding(s string) (r io.Reader, err error)
- func Unsetenv(envs ...string)
- func ViaTor() (addr string, err error)
- func WebPToPNG(src, dst string) error
- func Writable(dir string) error
- func WriteFile(path string, data []byte, mode os.FileMode) error
- type RewriteTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Byte2String ¶
Byte2String converts byte slice to a string without memory allocation.
func CheckContext ¶
func CheckContext(ctx context.Context, t leaktest.ErrorReporter)
CheckContext calls `leaktest.CheckContext` which is same as CheckTest, but uses a context.Context for cancellation and timeout control.
func CheckTest ¶
func CheckTest(t leaktest.ErrorReporter)
CheckTest calls `leaktest.Check` to snapshots the currently-running goroutines to be run at the end of tests to see whether any goroutines leaked, waiting up to 5 seconds in error conditions.
func CheckTimeout ¶
func CheckTimeout(t leaktest.ErrorReporter, d time.Duration)
CheckTimeout calls `leaktest.CheckTimeout` which is same as Check, but with a configurable timeout
func FileSize ¶
FileSeze returns file attritubes of size about an inode, and it's unit alway is bytes.
func FindChromeExecPath ¶
func FindChromeExecPath() string
FindChromeExecPath tries to find the Chrome browser somewhere in the current system. It finds in different locations on different OS systems. It could perform a rather aggressive search. That may make it a bit slow, but it will only be run when creating a new ExecAllocator. Fork from: https://github.com/chromedp/chromedp/blob/4ea2300cf7c7065242867bdcb8772533e0a66ea7/allocate.go#L352-L383
func MatchURLFallback ¶
MatchURLFallback is extract URL from text, and convert to Google cache endpoint if not found, returns []string always.
func MockServer ¶
MockServer returns an http Client, ServeMux, and Server. The client proxies requests to the server and handlers can be registered on the mux to handle requests. The caller must close the test server.
func RandString ¶
func RetryRemoveAll ¶
RetryRemoveAll will attempt to remove an item or directory up to the given number of retries. NOTE: This function is necessary because of a Windows bug with removing files that have been recently used: https://github.com/golang/go/issues/51442
func String2Byte ¶
String2Byte converts string to a byte slice without memory allocation.
func ViaTor ¶
ViaTor checks the Tor proxy whether running. Host and port listening by Tor defaults to 127.0.0.1 and 9050, they can be specific with `TOR_HOST` and `TOR_SOCKS_PORT` environments.
ViaTor returns address used by Tor, and an error if Tor proxy missing.
Types ¶
type RewriteTransport ¶
type RewriteTransport struct {
Transport http.RoundTripper
}
RewriteTransport rewrites https requests to http to avoid TLS cert issues during testing.