id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
26,900 | magefile/mage | mg/errors.go | Fatalf | func Fatalf(code int, format string, args ...interface{}) error {
return fatalErr{
code: code,
error: fmt.Errorf(format, args...),
}
} | go | func Fatalf(code int, format string, args ...interface{}) error {
return fatalErr{
code: code,
error: fmt.Errorf(format, args...),
}
} | [
"func",
"Fatalf",
"(",
"code",
"int",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"fatalErr",
"{",
"code",
":",
"code",
",",
"error",
":",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"args",
"...",
... | // Fatalf returns an error that will cause mage to print out the
// given message and exit with the given exit code. | [
"Fatalf",
"returns",
"an",
"error",
"that",
"will",
"cause",
"mage",
"to",
"print",
"out",
"the",
"given",
"message",
"and",
"exit",
"with",
"the",
"given",
"exit",
"code",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/errors.go#L32-L37 |
26,901 | magefile/mage | target/target.go | Dir | func Dir(dst string, sources ...string) (bool, error) {
stat, err := os.Stat(os.ExpandEnv(dst))
if os.IsNotExist(err) {
return true, nil
}
if err != nil {
return false, err
}
srcTime := stat.ModTime()
if stat.IsDir() {
srcTime, err = calDirModTimeRecursive(dst, stat)
if err != nil {
return false, err
... | go | func Dir(dst string, sources ...string) (bool, error) {
stat, err := os.Stat(os.ExpandEnv(dst))
if os.IsNotExist(err) {
return true, nil
}
if err != nil {
return false, err
}
srcTime := stat.ModTime()
if stat.IsDir() {
srcTime, err = calDirModTimeRecursive(dst, stat)
if err != nil {
return false, err
... | [
"func",
"Dir",
"(",
"dst",
"string",
",",
"sources",
"...",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"stat",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"os",
".",
"ExpandEnv",
"(",
"dst",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
... | // Dir reports whether any of the sources have been modified more recently than
// the destination. If a source or destination is a directory, modtimes of
// files under those directories are compared instead. If the destination file
// doesn't exist, it always returns true and nil. It's an error if any of the
// so... | [
"Dir",
"reports",
"whether",
"any",
"of",
"the",
"sources",
"have",
"been",
"modified",
"more",
"recently",
"than",
"the",
"destination",
".",
"If",
"a",
"source",
"or",
"destination",
"is",
"a",
"directory",
"modtimes",
"of",
"files",
"under",
"those",
"dir... | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/target/target.go#L79-L106 |
26,902 | magefile/mage | sh/cmd.go | OutCmd | func OutCmd(cmd string, args ...string) func(args ...string) (string, error) {
return func(args2 ...string) (string, error) {
return Output(cmd, append(args, args2...)...)
}
} | go | func OutCmd(cmd string, args ...string) func(args ...string) (string, error) {
return func(args2 ...string) (string, error) {
return Output(cmd, append(args, args2...)...)
}
} | [
"func",
"OutCmd",
"(",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"func",
"(",
"args",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"func",
"(",
"args2",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{"... | // OutCmd is like RunCmd except the command returns the output of the
// command. | [
"OutCmd",
"is",
"like",
"RunCmd",
"except",
"the",
"command",
"returns",
"the",
"output",
"of",
"the",
"command",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L42-L46 |
26,903 | magefile/mage | sh/cmd.go | Run | func Run(cmd string, args ...string) error {
return RunWith(nil, cmd, args...)
} | go | func Run(cmd string, args ...string) error {
return RunWith(nil, cmd, args...)
} | [
"func",
"Run",
"(",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"return",
"RunWith",
"(",
"nil",
",",
"cmd",
",",
"args",
"...",
")",
"\n",
"}"
] | // Run is like RunWith, but doesn't specify any environment variables. | [
"Run",
"is",
"like",
"RunWith",
"but",
"doesn",
"t",
"specify",
"any",
"environment",
"variables",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L49-L51 |
26,904 | magefile/mage | sh/cmd.go | RunV | func RunV(cmd string, args ...string) error {
_, err := Exec(nil, os.Stdout, os.Stderr, cmd, args...)
return err
} | go | func RunV(cmd string, args ...string) error {
_, err := Exec(nil, os.Stdout, os.Stderr, cmd, args...)
return err
} | [
"func",
"RunV",
"(",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"Exec",
"(",
"nil",
",",
"os",
".",
"Stdout",
",",
"os",
".",
"Stderr",
",",
"cmd",
",",
"args",
"...",
")",
"\n",
"return",
"err",
"\... | // RunV is like Run, but always sends the command's stdout to os.Stdout. | [
"RunV",
"is",
"like",
"Run",
"but",
"always",
"sends",
"the",
"command",
"s",
"stdout",
"to",
"os",
".",
"Stdout",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L54-L57 |
26,905 | magefile/mage | sh/cmd.go | RunWith | func RunWith(env map[string]string, cmd string, args ...string) error {
var output io.Writer
if mg.Verbose() {
output = os.Stdout
}
_, err := Exec(env, output, os.Stderr, cmd, args...)
return err
} | go | func RunWith(env map[string]string, cmd string, args ...string) error {
var output io.Writer
if mg.Verbose() {
output = os.Stdout
}
_, err := Exec(env, output, os.Stderr, cmd, args...)
return err
} | [
"func",
"RunWith",
"(",
"env",
"map",
"[",
"string",
"]",
"string",
",",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"var",
"output",
"io",
".",
"Writer",
"\n",
"if",
"mg",
".",
"Verbose",
"(",
")",
"{",
"output",
"=",
"os",
... | // RunWith runs the given command, directing stderr to this program's stderr and
// printing stdout to stdout if mage was run with -v. It adds adds env to the
// environment variables for the command being run. Environment variables should
// be in the format name=value. | [
"RunWith",
"runs",
"the",
"given",
"command",
"directing",
"stderr",
"to",
"this",
"program",
"s",
"stderr",
"and",
"printing",
"stdout",
"to",
"stdout",
"if",
"mage",
"was",
"run",
"with",
"-",
"v",
".",
"It",
"adds",
"adds",
"env",
"to",
"the",
"enviro... | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L63-L70 |
26,906 | magefile/mage | sh/cmd.go | Output | func Output(cmd string, args ...string) (string, error) {
buf := &bytes.Buffer{}
_, err := Exec(nil, buf, os.Stderr, cmd, args...)
return strings.TrimSuffix(buf.String(), "\n"), err
} | go | func Output(cmd string, args ...string) (string, error) {
buf := &bytes.Buffer{}
_, err := Exec(nil, buf, os.Stderr, cmd, args...)
return strings.TrimSuffix(buf.String(), "\n"), err
} | [
"func",
"Output",
"(",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"Exec",
"(",
"nil",
",",
"buf",
",",
"os",
".",
... | // Output runs the command and returns the text from stdout. | [
"Output",
"runs",
"the",
"command",
"and",
"returns",
"the",
"text",
"from",
"stdout",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L73-L77 |
26,907 | magefile/mage | sh/cmd.go | OutputWith | func OutputWith(env map[string]string, cmd string, args ...string) (string, error) {
buf := &bytes.Buffer{}
_, err := Exec(env, buf, os.Stderr, cmd, args...)
return strings.TrimSuffix(buf.String(), "\n"), err
} | go | func OutputWith(env map[string]string, cmd string, args ...string) (string, error) {
buf := &bytes.Buffer{}
_, err := Exec(env, buf, os.Stderr, cmd, args...)
return strings.TrimSuffix(buf.String(), "\n"), err
} | [
"func",
"OutputWith",
"(",
"env",
"map",
"[",
"string",
"]",
"string",
",",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"_",
",",
"err",
":="... | // OutputWith is like RunWith, but returns what is written to stdout. | [
"OutputWith",
"is",
"like",
"RunWith",
"but",
"returns",
"what",
"is",
"written",
"to",
"stdout",
"."
] | 5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed | https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/cmd.go#L80-L84 |
26,908 | appleboy/gin-jwt | auth_jwt.go | New | func New(m *GinJWTMiddleware) (*GinJWTMiddleware, error) {
if err := m.MiddlewareInit(); err != nil {
return nil, err
}
return m, nil
} | go | func New(m *GinJWTMiddleware) (*GinJWTMiddleware, error) {
if err := m.MiddlewareInit(); err != nil {
return nil, err
}
return m, nil
} | [
"func",
"New",
"(",
"m",
"*",
"GinJWTMiddleware",
")",
"(",
"*",
"GinJWTMiddleware",
",",
"error",
")",
"{",
"if",
"err",
":=",
"m",
".",
"MiddlewareInit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ret... | // New for check error with GinJWTMiddleware | [
"New",
"for",
"check",
"error",
"with",
"GinJWTMiddleware"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L193-L199 |
26,909 | appleboy/gin-jwt | auth_jwt.go | MiddlewareInit | func (mw *GinJWTMiddleware) MiddlewareInit() error {
if mw.TokenLookup == "" {
mw.TokenLookup = "header:Authorization"
}
if mw.SigningAlgorithm == "" {
mw.SigningAlgorithm = "HS256"
}
if mw.Timeout == 0 {
mw.Timeout = time.Hour
}
if mw.TimeFunc == nil {
mw.TimeFunc = time.Now
}
mw.TokenHeadName = ... | go | func (mw *GinJWTMiddleware) MiddlewareInit() error {
if mw.TokenLookup == "" {
mw.TokenLookup = "header:Authorization"
}
if mw.SigningAlgorithm == "" {
mw.SigningAlgorithm = "HS256"
}
if mw.Timeout == 0 {
mw.Timeout = time.Hour
}
if mw.TimeFunc == nil {
mw.TimeFunc = time.Now
}
mw.TokenHeadName = ... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"MiddlewareInit",
"(",
")",
"error",
"{",
"if",
"mw",
".",
"TokenLookup",
"==",
"\"",
"\"",
"{",
"mw",
".",
"TokenLookup",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"mw",
".",
"SigningAlgorithm",
"==",
... | // MiddlewareInit initialize jwt configs. | [
"MiddlewareInit",
"initialize",
"jwt",
"configs",
"."
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L248-L339 |
26,910 | appleboy/gin-jwt | auth_jwt.go | MiddlewareFunc | func (mw *GinJWTMiddleware) MiddlewareFunc() gin.HandlerFunc {
return func(c *gin.Context) {
mw.middlewareImpl(c)
}
} | go | func (mw *GinJWTMiddleware) MiddlewareFunc() gin.HandlerFunc {
return func(c *gin.Context) {
mw.middlewareImpl(c)
}
} | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"MiddlewareFunc",
"(",
")",
"gin",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"{",
"mw",
".",
"middlewareImpl",
"(",
"c",
")",
"\n",
"}",
"\n",
"}"
] | // MiddlewareFunc makes GinJWTMiddleware implement the Middleware interface. | [
"MiddlewareFunc",
"makes",
"GinJWTMiddleware",
"implement",
"the",
"Middleware",
"interface",
"."
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L342-L346 |
26,911 | appleboy/gin-jwt | auth_jwt.go | GetClaimsFromJWT | func (mw *GinJWTMiddleware) GetClaimsFromJWT(c *gin.Context) (MapClaims, error) {
token, err := mw.ParseToken(c)
if err != nil {
return nil, err
}
if mw.SendAuthorization {
if v, ok := c.Get("JWT_TOKEN"); ok {
c.Header("Authorization", mw.TokenHeadName+" "+v.(string))
}
}
claims := MapClaims{}
for ke... | go | func (mw *GinJWTMiddleware) GetClaimsFromJWT(c *gin.Context) (MapClaims, error) {
token, err := mw.ParseToken(c)
if err != nil {
return nil, err
}
if mw.SendAuthorization {
if v, ok := c.Get("JWT_TOKEN"); ok {
c.Header("Authorization", mw.TokenHeadName+" "+v.(string))
}
}
claims := MapClaims{}
for ke... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"GetClaimsFromJWT",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"(",
"MapClaims",
",",
"error",
")",
"{",
"token",
",",
"err",
":=",
"mw",
".",
"ParseToken",
"(",
"c",
")",
"\n\n",
"if",
"err",
"!=",
... | // GetClaimsFromJWT get claims from JWT token | [
"GetClaimsFromJWT",
"get",
"claims",
"from",
"JWT",
"token"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L386-L405 |
26,912 | appleboy/gin-jwt | auth_jwt.go | RefreshToken | func (mw *GinJWTMiddleware) RefreshToken(c *gin.Context) (string, time.Time, error) {
claims, err := mw.CheckIfTokenExpire(c)
if err != nil {
return "", time.Now(), err
}
// Create the token
newToken := jwt.New(jwt.GetSigningMethod(mw.SigningAlgorithm))
newClaims := newToken.Claims.(jwt.MapClaims)
for key :=... | go | func (mw *GinJWTMiddleware) RefreshToken(c *gin.Context) (string, time.Time, error) {
claims, err := mw.CheckIfTokenExpire(c)
if err != nil {
return "", time.Now(), err
}
// Create the token
newToken := jwt.New(jwt.GetSigningMethod(mw.SigningAlgorithm))
newClaims := newToken.Claims.(jwt.MapClaims)
for key :=... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"RefreshToken",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"(",
"string",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"claims",
",",
"err",
":=",
"mw",
".",
"CheckIfTokenExpire",
"(",
"c",
")",
... | // RefreshToken refresh token and check if token is expired | [
"RefreshToken",
"refresh",
"token",
"and",
"check",
"if",
"token",
"is",
"expired"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L485-L523 |
26,913 | appleboy/gin-jwt | auth_jwt.go | CheckIfTokenExpire | func (mw *GinJWTMiddleware) CheckIfTokenExpire(c *gin.Context) (jwt.MapClaims, error) {
token, err := mw.ParseToken(c)
if err != nil {
// If we receive an error, and the error is anything other than a single
// ValidationErrorExpired, we want to return the error.
// If the error is just ValidationErrorExpired,... | go | func (mw *GinJWTMiddleware) CheckIfTokenExpire(c *gin.Context) (jwt.MapClaims, error) {
token, err := mw.ParseToken(c)
if err != nil {
// If we receive an error, and the error is anything other than a single
// ValidationErrorExpired, we want to return the error.
// If the error is just ValidationErrorExpired,... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"CheckIfTokenExpire",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"(",
"jwt",
".",
"MapClaims",
",",
"error",
")",
"{",
"token",
",",
"err",
":=",
"mw",
".",
"ParseToken",
"(",
"c",
")",
"\n\n",
"if",
... | // CheckIfTokenExpire check if token expire | [
"CheckIfTokenExpire",
"check",
"if",
"token",
"expire"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L526-L550 |
26,914 | appleboy/gin-jwt | auth_jwt.go | TokenGenerator | func (mw *GinJWTMiddleware) TokenGenerator(data interface{}) (string, time.Time, error) {
token := jwt.New(jwt.GetSigningMethod(mw.SigningAlgorithm))
claims := token.Claims.(jwt.MapClaims)
if mw.PayloadFunc != nil {
for key, value := range mw.PayloadFunc(data) {
claims[key] = value
}
}
expire := mw.TimeFu... | go | func (mw *GinJWTMiddleware) TokenGenerator(data interface{}) (string, time.Time, error) {
token := jwt.New(jwt.GetSigningMethod(mw.SigningAlgorithm))
claims := token.Claims.(jwt.MapClaims)
if mw.PayloadFunc != nil {
for key, value := range mw.PayloadFunc(data) {
claims[key] = value
}
}
expire := mw.TimeFu... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"TokenGenerator",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"token",
":=",
"jwt",
".",
"New",
"(",
"jwt",
".",
"GetSigningMethod",
"(",
"... | // TokenGenerator method that clients can use to get a jwt token. | [
"TokenGenerator",
"method",
"that",
"clients",
"can",
"use",
"to",
"get",
"a",
"jwt",
"token",
"."
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L553-L572 |
26,915 | appleboy/gin-jwt | auth_jwt.go | ParseToken | func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) {
var token string
var err error
methods := strings.Split(mw.TokenLookup, ",")
for _, method := range methods {
if len(token) > 0 {
break
}
parts := strings.Split(strings.TrimSpace(method), ":")
k := strings.TrimSpace(parts[0])
... | go | func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) {
var token string
var err error
methods := strings.Split(mw.TokenLookup, ",")
for _, method := range methods {
if len(token) > 0 {
break
}
parts := strings.Split(strings.TrimSpace(method), ":")
k := strings.TrimSpace(parts[0])
... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"ParseToken",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"(",
"*",
"jwt",
".",
"Token",
",",
"error",
")",
"{",
"var",
"token",
"string",
"\n",
"var",
"err",
"error",
"\n\n",
"methods",
":=",
"strings"... | // ParseToken parse jwt token from gin context | [
"ParseToken",
"parse",
"jwt",
"token",
"from",
"gin",
"context"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L620-L661 |
26,916 | appleboy/gin-jwt | auth_jwt.go | ParseTokenString | func (mw *GinJWTMiddleware) ParseTokenString(token string) (*jwt.Token, error) {
return jwt.Parse(token, func(t *jwt.Token) (interface{}, error) {
if jwt.GetSigningMethod(mw.SigningAlgorithm) != t.Method {
return nil, ErrInvalidSigningAlgorithm
}
if mw.usingPublicKeyAlgo() {
return mw.pubKey, nil
}
re... | go | func (mw *GinJWTMiddleware) ParseTokenString(token string) (*jwt.Token, error) {
return jwt.Parse(token, func(t *jwt.Token) (interface{}, error) {
if jwt.GetSigningMethod(mw.SigningAlgorithm) != t.Method {
return nil, ErrInvalidSigningAlgorithm
}
if mw.usingPublicKeyAlgo() {
return mw.pubKey, nil
}
re... | [
"func",
"(",
"mw",
"*",
"GinJWTMiddleware",
")",
"ParseTokenString",
"(",
"token",
"string",
")",
"(",
"*",
"jwt",
".",
"Token",
",",
"error",
")",
"{",
"return",
"jwt",
".",
"Parse",
"(",
"token",
",",
"func",
"(",
"t",
"*",
"jwt",
".",
"Token",
"... | // ParseTokenString parse jwt token string | [
"ParseTokenString",
"parse",
"jwt",
"token",
"string"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L664-L675 |
26,917 | appleboy/gin-jwt | auth_jwt.go | ExtractClaims | func ExtractClaims(c *gin.Context) MapClaims {
claims, exists := c.Get("JWT_PAYLOAD")
if !exists {
return make(MapClaims)
}
return claims.(MapClaims)
} | go | func ExtractClaims(c *gin.Context) MapClaims {
claims, exists := c.Get("JWT_PAYLOAD")
if !exists {
return make(MapClaims)
}
return claims.(MapClaims)
} | [
"func",
"ExtractClaims",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"MapClaims",
"{",
"claims",
",",
"exists",
":=",
"c",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"exists",
"{",
"return",
"make",
"(",
"MapClaims",
")",
"\n",
"}",
"\n\n",
... | // ExtractClaims help to extract the JWT claims | [
"ExtractClaims",
"help",
"to",
"extract",
"the",
"JWT",
"claims"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L687-L694 |
26,918 | appleboy/gin-jwt | auth_jwt.go | ExtractClaimsFromToken | func ExtractClaimsFromToken(token *jwt.Token) MapClaims {
if token == nil {
return make(MapClaims)
}
claims := MapClaims{}
for key, value := range token.Claims.(jwt.MapClaims) {
claims[key] = value
}
return claims
} | go | func ExtractClaimsFromToken(token *jwt.Token) MapClaims {
if token == nil {
return make(MapClaims)
}
claims := MapClaims{}
for key, value := range token.Claims.(jwt.MapClaims) {
claims[key] = value
}
return claims
} | [
"func",
"ExtractClaimsFromToken",
"(",
"token",
"*",
"jwt",
".",
"Token",
")",
"MapClaims",
"{",
"if",
"token",
"==",
"nil",
"{",
"return",
"make",
"(",
"MapClaims",
")",
"\n",
"}",
"\n\n",
"claims",
":=",
"MapClaims",
"{",
"}",
"\n",
"for",
"key",
","... | // ExtractClaimsFromToken help to extract the JWT claims from token | [
"ExtractClaimsFromToken",
"help",
"to",
"extract",
"the",
"JWT",
"claims",
"from",
"token"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L697-L708 |
26,919 | appleboy/gin-jwt | auth_jwt.go | GetToken | func GetToken(c *gin.Context) string {
token, exists := c.Get("JWT_TOKEN")
if !exists {
return ""
}
return token.(string)
} | go | func GetToken(c *gin.Context) string {
token, exists := c.Get("JWT_TOKEN")
if !exists {
return ""
}
return token.(string)
} | [
"func",
"GetToken",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"string",
"{",
"token",
",",
"exists",
":=",
"c",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"exists",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"token",
".",
... | // GetToken help to get the JWT token string | [
"GetToken",
"help",
"to",
"get",
"the",
"JWT",
"token",
"string"
] | 633d983b91f09beefb1128c4558d4642a379c602 | https://github.com/appleboy/gin-jwt/blob/633d983b91f09beefb1128c4558d4642a379c602/auth_jwt.go#L711-L718 |
26,920 | brianvoe/gofakeit | user_agent.go | UserAgent | func UserAgent() string {
randNum := randIntRange(0, 4)
switch randNum {
case 0:
return ChromeUserAgent()
case 1:
return FirefoxUserAgent()
case 2:
return SafariUserAgent()
case 3:
return OperaUserAgent()
default:
return ChromeUserAgent()
}
} | go | func UserAgent() string {
randNum := randIntRange(0, 4)
switch randNum {
case 0:
return ChromeUserAgent()
case 1:
return FirefoxUserAgent()
case 2:
return SafariUserAgent()
case 3:
return OperaUserAgent()
default:
return ChromeUserAgent()
}
} | [
"func",
"UserAgent",
"(",
")",
"string",
"{",
"randNum",
":=",
"randIntRange",
"(",
"0",
",",
"4",
")",
"\n",
"switch",
"randNum",
"{",
"case",
"0",
":",
"return",
"ChromeUserAgent",
"(",
")",
"\n",
"case",
"1",
":",
"return",
"FirefoxUserAgent",
"(",
... | // UserAgent will generate a random broswer user agent | [
"UserAgent",
"will",
"generate",
"a",
"random",
"broswer",
"user",
"agent"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L6-L20 |
26,921 | brianvoe/gofakeit | user_agent.go | ChromeUserAgent | func ChromeUserAgent() string {
randNum1 := strconv.Itoa(randIntRange(531, 536)) + strconv.Itoa(randIntRange(0, 2))
randNum2 := strconv.Itoa(randIntRange(36, 40))
randNum3 := strconv.Itoa(randIntRange(800, 899))
return "Mozilla/5.0 " + "(" + randomPlatform() + ") AppleWebKit/" + randNum1 + " (KHTML, like Gecko) Chr... | go | func ChromeUserAgent() string {
randNum1 := strconv.Itoa(randIntRange(531, 536)) + strconv.Itoa(randIntRange(0, 2))
randNum2 := strconv.Itoa(randIntRange(36, 40))
randNum3 := strconv.Itoa(randIntRange(800, 899))
return "Mozilla/5.0 " + "(" + randomPlatform() + ") AppleWebKit/" + randNum1 + " (KHTML, like Gecko) Chr... | [
"func",
"ChromeUserAgent",
"(",
")",
"string",
"{",
"randNum1",
":=",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"531",
",",
"536",
")",
")",
"+",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"0",
",",
"2",
")",
")",
"\n",
"randNum2",
":=... | // ChromeUserAgent will generate a random chrome browser user agent string | [
"ChromeUserAgent",
"will",
"generate",
"a",
"random",
"chrome",
"browser",
"user",
"agent",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L23-L28 |
26,922 | brianvoe/gofakeit | user_agent.go | FirefoxUserAgent | func FirefoxUserAgent() string {
ver := "Gecko/" + Date().Format("2006-02-01") + " Firefox/" + strconv.Itoa(randIntRange(35, 37)) + ".0"
platforms := []string{
"(" + windowsPlatformToken() + "; " + "en-US" + "; rv:1.9." + strconv.Itoa(randIntRange(0, 3)) + ".20) " + ver,
"(" + linuxPlatformToken() + "; rv:" + str... | go | func FirefoxUserAgent() string {
ver := "Gecko/" + Date().Format("2006-02-01") + " Firefox/" + strconv.Itoa(randIntRange(35, 37)) + ".0"
platforms := []string{
"(" + windowsPlatformToken() + "; " + "en-US" + "; rv:1.9." + strconv.Itoa(randIntRange(0, 3)) + ".20) " + ver,
"(" + linuxPlatformToken() + "; rv:" + str... | [
"func",
"FirefoxUserAgent",
"(",
")",
"string",
"{",
"ver",
":=",
"\"",
"\"",
"+",
"Date",
"(",
")",
".",
"Format",
"(",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"35",
",",
"37",
")",
")",
"+",
"\... | // FirefoxUserAgent will generate a random firefox broswer user agent string | [
"FirefoxUserAgent",
"will",
"generate",
"a",
"random",
"firefox",
"broswer",
"user",
"agent",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L31-L40 |
26,923 | brianvoe/gofakeit | user_agent.go | SafariUserAgent | func SafariUserAgent() string {
randNum := strconv.Itoa(randIntRange(531, 536)) + "." + strconv.Itoa(randIntRange(1, 51)) + "." + strconv.Itoa(randIntRange(1, 8))
ver := strconv.Itoa(randIntRange(4, 6)) + "." + strconv.Itoa(randIntRange(0, 2))
mobileDevices := []string{
"iPhone; CPU iPhone OS",
"iPad; CPU OS",
... | go | func SafariUserAgent() string {
randNum := strconv.Itoa(randIntRange(531, 536)) + "." + strconv.Itoa(randIntRange(1, 51)) + "." + strconv.Itoa(randIntRange(1, 8))
ver := strconv.Itoa(randIntRange(4, 6)) + "." + strconv.Itoa(randIntRange(0, 2))
mobileDevices := []string{
"iPhone; CPU iPhone OS",
"iPad; CPU OS",
... | [
"func",
"SafariUserAgent",
"(",
")",
"string",
"{",
"randNum",
":=",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"531",
",",
"536",
")",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"1",
",",
"51",
")",
")",
"+... | // SafariUserAgent will generate a random safari browser user agent string | [
"SafariUserAgent",
"will",
"generate",
"a",
"random",
"safari",
"browser",
"user",
"agent",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L43-L59 |
26,924 | brianvoe/gofakeit | user_agent.go | OperaUserAgent | func OperaUserAgent() string {
platform := "(" + randomPlatform() + "; en-US) Presto/2." + strconv.Itoa(randIntRange(8, 13)) + "." + strconv.Itoa(randIntRange(160, 355)) + " Version/" + strconv.Itoa(randIntRange(10, 13)) + ".00"
return "Opera/" + strconv.Itoa(randIntRange(8, 10)) + "." + strconv.Itoa(randIntRange(10... | go | func OperaUserAgent() string {
platform := "(" + randomPlatform() + "; en-US) Presto/2." + strconv.Itoa(randIntRange(8, 13)) + "." + strconv.Itoa(randIntRange(160, 355)) + " Version/" + strconv.Itoa(randIntRange(10, 13)) + ".00"
return "Opera/" + strconv.Itoa(randIntRange(8, 10)) + "." + strconv.Itoa(randIntRange(10... | [
"func",
"OperaUserAgent",
"(",
")",
"string",
"{",
"platform",
":=",
"\"",
"\"",
"+",
"randomPlatform",
"(",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"8",
",",
"13",
")",
")",
"+",
"\"",
"\"",
"+",
"strconv",
"."... | // OperaUserAgent will generate a random opera browser user agent string | [
"OperaUserAgent",
"will",
"generate",
"a",
"random",
"opera",
"browser",
"user",
"agent",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L62-L66 |
26,925 | brianvoe/gofakeit | user_agent.go | macPlatformToken | func macPlatformToken() string {
return "Macintosh; " + getRandValue([]string{"computer", "mac_processor"}) + " Mac OS X 10_" + strconv.Itoa(randIntRange(5, 9)) + "_" + strconv.Itoa(randIntRange(0, 10))
} | go | func macPlatformToken() string {
return "Macintosh; " + getRandValue([]string{"computer", "mac_processor"}) + " Mac OS X 10_" + strconv.Itoa(randIntRange(5, 9)) + "_" + strconv.Itoa(randIntRange(0, 10))
} | [
"func",
"macPlatformToken",
"(",
")",
"string",
"{",
"return",
"\"",
"\"",
"+",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"5",
",",
... | // macPlatformToken will generate a random mac platform | [
"macPlatformToken",
"will",
"generate",
"a",
"random",
"mac",
"platform"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/user_agent.go#L74-L76 |
26,926 | brianvoe/gofakeit | address.go | Address | func Address() *AddressInfo {
street := Street()
city := City()
state := State()
zip := Zip()
return &AddressInfo{
Address: street + ", " + city + ", " + state + " " + zip,
Street: street,
City: city,
State: state,
Zip: zip,
Country: Country(),
Latitude: Latitude(),
Longitud... | go | func Address() *AddressInfo {
street := Street()
city := City()
state := State()
zip := Zip()
return &AddressInfo{
Address: street + ", " + city + ", " + state + " " + zip,
Street: street,
City: city,
State: state,
Zip: zip,
Country: Country(),
Latitude: Latitude(),
Longitud... | [
"func",
"Address",
"(",
")",
"*",
"AddressInfo",
"{",
"street",
":=",
"Street",
"(",
")",
"\n",
"city",
":=",
"City",
"(",
")",
"\n",
"state",
":=",
"State",
"(",
")",
"\n",
"zip",
":=",
"Zip",
"(",
")",
"\n\n",
"return",
"&",
"AddressInfo",
"{",
... | // Address will generate a struct of address information | [
"Address",
"will",
"generate",
"a",
"struct",
"of",
"address",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/address.go#L22-L38 |
26,927 | brianvoe/gofakeit | address.go | Street | func Street() (street string) {
switch randInt := randIntRange(1, 2); randInt {
case 1:
street = StreetNumber() + " " + StreetPrefix() + " " + StreetName() + StreetSuffix()
case 2:
street = StreetNumber() + " " + StreetName() + StreetSuffix()
}
return
} | go | func Street() (street string) {
switch randInt := randIntRange(1, 2); randInt {
case 1:
street = StreetNumber() + " " + StreetPrefix() + " " + StreetName() + StreetSuffix()
case 2:
street = StreetNumber() + " " + StreetName() + StreetSuffix()
}
return
} | [
"func",
"Street",
"(",
")",
"(",
"street",
"string",
")",
"{",
"switch",
"randInt",
":=",
"randIntRange",
"(",
"1",
",",
"2",
")",
";",
"randInt",
"{",
"case",
"1",
":",
"street",
"=",
"StreetNumber",
"(",
")",
"+",
"\"",
"\"",
"+",
"StreetPrefix",
... | // Street will generate a random address street string | [
"Street",
"will",
"generate",
"a",
"random",
"address",
"street",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/address.go#L41-L50 |
26,928 | brianvoe/gofakeit | address.go | City | func City() (city string) {
switch randInt := randIntRange(1, 3); randInt {
case 1:
city = FirstName() + StreetSuffix()
case 2:
city = LastName() + StreetSuffix()
case 3:
city = StreetPrefix() + " " + LastName()
}
return
} | go | func City() (city string) {
switch randInt := randIntRange(1, 3); randInt {
case 1:
city = FirstName() + StreetSuffix()
case 2:
city = LastName() + StreetSuffix()
case 3:
city = StreetPrefix() + " " + LastName()
}
return
} | [
"func",
"City",
"(",
")",
"(",
"city",
"string",
")",
"{",
"switch",
"randInt",
":=",
"randIntRange",
"(",
"1",
",",
"3",
")",
";",
"randInt",
"{",
"case",
"1",
":",
"city",
"=",
"FirstName",
"(",
")",
"+",
"StreetSuffix",
"(",
")",
"\n",
"case",
... | // City will generate a random city string | [
"City",
"will",
"generate",
"a",
"random",
"city",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/address.go#L73-L84 |
26,929 | brianvoe/gofakeit | address.go | LongitudeInRange | func LongitudeInRange(min, max float64) (float64, error) {
if min > max || min < -180 || min > 180 || max < -180 || max > 180 {
return 0, errors.New("input range is invalid")
}
return randFloat64Range(min, max), nil
} | go | func LongitudeInRange(min, max float64) (float64, error) {
if min > max || min < -180 || min > 180 || max < -180 || max > 180 {
return 0, errors.New("input range is invalid")
}
return randFloat64Range(min, max), nil
} | [
"func",
"LongitudeInRange",
"(",
"min",
",",
"max",
"float64",
")",
"(",
"float64",
",",
"error",
")",
"{",
"if",
"min",
">",
"max",
"||",
"min",
"<",
"-",
"180",
"||",
"min",
">",
"180",
"||",
"max",
"<",
"-",
"180",
"||",
"max",
">",
"180",
"... | // LongitudeInRange will generate a random longitude within the input range | [
"LongitudeInRange",
"will",
"generate",
"a",
"random",
"longitude",
"within",
"the",
"input",
"range"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/address.go#L126-L131 |
26,930 | brianvoe/gofakeit | misc.go | getRandValue | func getRandValue(dataVal []string) string {
if !dataCheck(dataVal) {
return ""
}
return data.Data[dataVal[0]][dataVal[1]][rand.Intn(len(data.Data[dataVal[0]][dataVal[1]]))]
} | go | func getRandValue(dataVal []string) string {
if !dataCheck(dataVal) {
return ""
}
return data.Data[dataVal[0]][dataVal[1]][rand.Intn(len(data.Data[dataVal[0]][dataVal[1]]))]
} | [
"func",
"getRandValue",
"(",
"dataVal",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"!",
"dataCheck",
"(",
"dataVal",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"data",
".",
"Data",
"[",
"dataVal",
"[",
"0",
"]",
"]",
"[",
"dataVa... | // Get Random Value | [
"Get",
"Random",
"Value"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/misc.go#L41-L46 |
26,931 | brianvoe/gofakeit | misc.go | getRandIntValue | func getRandIntValue(dataVal []string) int {
if !intDataCheck(dataVal) {
return 0
}
return data.IntData[dataVal[0]][dataVal[1]][rand.Intn(len(data.IntData[dataVal[0]][dataVal[1]]))]
} | go | func getRandIntValue(dataVal []string) int {
if !intDataCheck(dataVal) {
return 0
}
return data.IntData[dataVal[0]][dataVal[1]][rand.Intn(len(data.IntData[dataVal[0]][dataVal[1]]))]
} | [
"func",
"getRandIntValue",
"(",
"dataVal",
"[",
"]",
"string",
")",
"int",
"{",
"if",
"!",
"intDataCheck",
"(",
"dataVal",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"data",
".",
"IntData",
"[",
"dataVal",
"[",
"0",
"]",
"]",
"[",
"dataVal",... | // Get Random Integer Value | [
"Get",
"Random",
"Integer",
"Value"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/misc.go#L49-L54 |
26,932 | brianvoe/gofakeit | misc.go | replaceWithLetters | func replaceWithLetters(str string) string {
if str == "" {
return str
}
bytestr := []byte(str)
for i := 0; i < len(bytestr); i++ {
if bytestr[i] == questionmark {
bytestr[i] = byte(randLetter())
}
}
return string(bytestr)
} | go | func replaceWithLetters(str string) string {
if str == "" {
return str
}
bytestr := []byte(str)
for i := 0; i < len(bytestr); i++ {
if bytestr[i] == questionmark {
bytestr[i] = byte(randLetter())
}
}
return string(bytestr)
} | [
"func",
"replaceWithLetters",
"(",
"str",
"string",
")",
"string",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"str",
"\n",
"}",
"\n",
"bytestr",
":=",
"[",
"]",
"byte",
"(",
"str",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
... | // Replace ? with ASCII lowercase letters | [
"Replace",
"?",
"with",
"ASCII",
"lowercase",
"letters"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/misc.go#L75-L87 |
26,933 | brianvoe/gofakeit | misc.go | randIntRange | func randIntRange(min, max int) int {
if min == max {
return min
}
return rand.Intn((max+1)-min) + min
} | go | func randIntRange(min, max int) int {
if min == max {
return min
}
return rand.Intn((max+1)-min) + min
} | [
"func",
"randIntRange",
"(",
"min",
",",
"max",
"int",
")",
"int",
"{",
"if",
"min",
"==",
"max",
"{",
"return",
"min",
"\n",
"}",
"\n",
"return",
"rand",
".",
"Intn",
"(",
"(",
"max",
"+",
"1",
")",
"-",
"min",
")",
"+",
"min",
"\n",
"}"
] | // Generate random integer between min and max | [
"Generate",
"random",
"integer",
"between",
"min",
"and",
"max"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/misc.go#L100-L105 |
26,934 | brianvoe/gofakeit | misc.go | Categories | func Categories() map[string][]string {
types := make(map[string][]string)
for category, subCategoriesMap := range data.Data {
subCategories := make([]string, 0)
for subType := range subCategoriesMap {
subCategories = append(subCategories, subType)
}
types[category] = subCategories
}
return types
} | go | func Categories() map[string][]string {
types := make(map[string][]string)
for category, subCategoriesMap := range data.Data {
subCategories := make([]string, 0)
for subType := range subCategoriesMap {
subCategories = append(subCategories, subType)
}
types[category] = subCategories
}
return types
} | [
"func",
"Categories",
"(",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"types",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n",
"for",
"category",
",",
"subCategoriesMap",
":=",
"range",
"data",
".",
"Data",
... | // Categories will return a map string array of available data categories and sub categories | [
"Categories",
"will",
"return",
"a",
"map",
"string",
"array",
"of",
"available",
"data",
"categories",
"and",
"sub",
"categories"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/misc.go#L122-L132 |
26,935 | brianvoe/gofakeit | password.go | Password | func Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string {
// Make sure the num minimun is at least 5
if num < 5 {
num = 5
}
i := 0
b := make([]byte, num)
var passString string
if lower {
passString += lowerStr
b[i] = lowerStr[rand.Int63()%int64(len(lowerStr))]
i++
... | go | func Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string {
// Make sure the num minimun is at least 5
if num < 5 {
num = 5
}
i := 0
b := make([]byte, num)
var passString string
if lower {
passString += lowerStr
b[i] = lowerStr[rand.Int63()%int64(len(lowerStr))]
i++
... | [
"func",
"Password",
"(",
"lower",
"bool",
",",
"upper",
"bool",
",",
"numeric",
"bool",
",",
"special",
"bool",
",",
"space",
"bool",
",",
"num",
"int",
")",
"string",
"{",
"// Make sure the num minimun is at least 5",
"if",
"num",
"<",
"5",
"{",
"num",
"=... | // Password will generate a random password
// Minimum number length of 5 if less than | [
"Password",
"will",
"generate",
"a",
"random",
"password",
"Minimum",
"number",
"length",
"of",
"5",
"if",
"less",
"than"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/password.go#L15-L68 |
26,936 | brianvoe/gofakeit | currency.go | Currency | func Currency() *CurrencyInfo {
index := rand.Intn(len(data.Data["currency"]["short"]))
return &CurrencyInfo{
Short: data.Data["currency"]["short"][index],
Long: data.Data["currency"]["long"][index],
}
} | go | func Currency() *CurrencyInfo {
index := rand.Intn(len(data.Data["currency"]["short"]))
return &CurrencyInfo{
Short: data.Data["currency"]["short"][index],
Long: data.Data["currency"]["long"][index],
}
} | [
"func",
"Currency",
"(",
")",
"*",
"CurrencyInfo",
"{",
"index",
":=",
"rand",
".",
"Intn",
"(",
"len",
"(",
"data",
".",
"Data",
"[",
"\"",
"\"",
"]",
"[",
"\"",
"\"",
"]",
")",
")",
"\n",
"return",
"&",
"CurrencyInfo",
"{",
"Short",
":",
"data"... | // Currency will generate a struct with random currency information | [
"Currency",
"will",
"generate",
"a",
"struct",
"with",
"random",
"currency",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/currency.go#L17-L23 |
26,937 | brianvoe/gofakeit | currency.go | Price | func Price(min, max float64) float64 {
return math.Floor(randFloat64Range(min, max)*100) / 100
} | go | func Price(min, max float64) float64 {
return math.Floor(randFloat64Range(min, max)*100) / 100
} | [
"func",
"Price",
"(",
"min",
",",
"max",
"float64",
")",
"float64",
"{",
"return",
"math",
".",
"Floor",
"(",
"randFloat64Range",
"(",
"min",
",",
"max",
")",
"*",
"100",
")",
"/",
"100",
"\n",
"}"
] | // Price will take in a min and max value and return a formatted price | [
"Price",
"will",
"take",
"in",
"a",
"min",
"and",
"max",
"value",
"and",
"return",
"a",
"formatted",
"price"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/currency.go#L36-L38 |
26,938 | brianvoe/gofakeit | words.go | Paragraph | func Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
return paragraphGenerator(paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, Sentence)
} | go | func Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
return paragraphGenerator(paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, Sentence)
} | [
"func",
"Paragraph",
"(",
"paragraphCount",
"int",
",",
"sentenceCount",
"int",
",",
"wordCount",
"int",
",",
"separator",
"string",
")",
"string",
"{",
"return",
"paragraphGenerator",
"(",
"paragrapOptions",
"{",
"paragraphCount",
",",
"sentenceCount",
",",
"word... | // Paragraph will generate a random paragraphGenerator
// Set Paragraph Count
// Set Sentence Count
// Set Word Count
// Set Paragraph Separator | [
"Paragraph",
"will",
"generate",
"a",
"random",
"paragraphGenerator",
"Set",
"Paragraph",
"Count",
"Set",
"Sentence",
"Count",
"Set",
"Word",
"Count",
"Set",
"Paragraph",
"Separator"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/words.go#L36-L38 |
26,939 | brianvoe/gofakeit | payment.go | CreditCard | func CreditCard() *CreditCardInfo {
return &CreditCardInfo{
Type: CreditCardType(),
Number: CreditCardNumber(),
Exp: CreditCardExp(),
Cvv: CreditCardCvv(),
}
} | go | func CreditCard() *CreditCardInfo {
return &CreditCardInfo{
Type: CreditCardType(),
Number: CreditCardNumber(),
Exp: CreditCardExp(),
Cvv: CreditCardCvv(),
}
} | [
"func",
"CreditCard",
"(",
")",
"*",
"CreditCardInfo",
"{",
"return",
"&",
"CreditCardInfo",
"{",
"Type",
":",
"CreditCardType",
"(",
")",
",",
"Number",
":",
"CreditCardNumber",
"(",
")",
",",
"Exp",
":",
"CreditCardExp",
"(",
")",
",",
"Cvv",
":",
"Cre... | // CreditCard will generate a struct full of credit card information | [
"CreditCard",
"will",
"generate",
"a",
"struct",
"full",
"of",
"credit",
"card",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/payment.go#L17-L24 |
26,940 | brianvoe/gofakeit | payment.go | CreditCardNumber | func CreditCardNumber() int {
integer, _ := strconv.Atoi(replaceWithNumbers(getRandValue([]string{"payment", "number"})))
return integer
} | go | func CreditCardNumber() int {
integer, _ := strconv.Atoi(replaceWithNumbers(getRandValue([]string{"payment", "number"})))
return integer
} | [
"func",
"CreditCardNumber",
"(",
")",
"int",
"{",
"integer",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"replaceWithNumbers",
"(",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
")",
")",
"\n",
"return",
"integ... | // CreditCardNumber will generate a random credit card number int | [
"CreditCardNumber",
"will",
"generate",
"a",
"random",
"credit",
"card",
"number",
"int"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/payment.go#L32-L35 |
26,941 | brianvoe/gofakeit | payment.go | CreditCardNumberLuhn | func CreditCardNumberLuhn() int {
cc := ""
for i := 0; i < 100000; i++ {
cc = replaceWithNumbers(getRandValue([]string{"payment", "number"}))
if luhn(cc) {
break
}
}
integer, _ := strconv.Atoi(cc)
return integer
} | go | func CreditCardNumberLuhn() int {
cc := ""
for i := 0; i < 100000; i++ {
cc = replaceWithNumbers(getRandValue([]string{"payment", "number"}))
if luhn(cc) {
break
}
}
integer, _ := strconv.Atoi(cc)
return integer
} | [
"func",
"CreditCardNumberLuhn",
"(",
")",
"int",
"{",
"cc",
":=",
"\"",
"\"",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"100000",
";",
"i",
"++",
"{",
"cc",
"=",
"replaceWithNumbers",
"(",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",... | // CreditCardNumberLuhn will generate a random credit card number int that passes luhn test | [
"CreditCardNumberLuhn",
"will",
"generate",
"a",
"random",
"credit",
"card",
"number",
"int",
"that",
"passes",
"luhn",
"test"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/payment.go#L38-L48 |
26,942 | brianvoe/gofakeit | payment.go | CreditCardExp | func CreditCardExp() string {
month := strconv.Itoa(randIntRange(1, 12))
if len(month) == 1 {
month = "0" + month
}
return month + "/" + strconv.Itoa(randIntRange(currentYear+1, currentYear+10))
} | go | func CreditCardExp() string {
month := strconv.Itoa(randIntRange(1, 12))
if len(month) == 1 {
month = "0" + month
}
return month + "/" + strconv.Itoa(randIntRange(currentYear+1, currentYear+10))
} | [
"func",
"CreditCardExp",
"(",
")",
"string",
"{",
"month",
":=",
"strconv",
".",
"Itoa",
"(",
"randIntRange",
"(",
"1",
",",
"12",
")",
")",
"\n",
"if",
"len",
"(",
"month",
")",
"==",
"1",
"{",
"month",
"=",
"\"",
"\"",
"+",
"month",
"\n",
"}",
... | // CreditCardExp will generate a random credit card expiration date string
// Exp date will always be a future date | [
"CreditCardExp",
"will",
"generate",
"a",
"random",
"credit",
"card",
"expiration",
"date",
"string",
"Exp",
"date",
"will",
"always",
"be",
"a",
"future",
"date"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/payment.go#L52-L58 |
26,943 | brianvoe/gofakeit | payment.go | luhn | func luhn(s string) bool {
var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
odd := len(s) & 1
var sum int
for i, c := range s {
if c < '0' || c > '9' {
return false
}
if i&1 == odd {
sum += t[c-'0']
} else {
sum += int(c - '0')
}
}
return sum%10 == 0
} | go | func luhn(s string) bool {
var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
odd := len(s) & 1
var sum int
for i, c := range s {
if c < '0' || c > '9' {
return false
}
if i&1 == odd {
sum += t[c-'0']
} else {
sum += int(c - '0')
}
}
return sum%10 == 0
} | [
"func",
"luhn",
"(",
"s",
"string",
")",
"bool",
"{",
"var",
"t",
"=",
"[",
"...",
"]",
"int",
"{",
"0",
",",
"2",
",",
"4",
",",
"6",
",",
"8",
",",
"1",
",",
"3",
",",
"5",
",",
"7",
",",
"9",
"}",
"\n",
"odd",
":=",
"len",
"(",
"s"... | // luhn check is used for checking if credit card is valid | [
"luhn",
"check",
"is",
"used",
"for",
"checking",
"if",
"credit",
"card",
"is",
"valid"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/payment.go#L66-L81 |
26,944 | brianvoe/gofakeit | color.go | HexColor | func HexColor() string {
color := make([]byte, 6)
hashQuestion := []byte("?#")
for i := 0; i < 6; i++ {
color[i] = hashQuestion[rand.Intn(2)]
}
return "#" + replaceWithLetters(replaceWithNumbers(string(color)))
// color := ""
// for i := 1; i <= 6; i++ {
// color += RandString([]string{"?", "#"})
// }
/... | go | func HexColor() string {
color := make([]byte, 6)
hashQuestion := []byte("?#")
for i := 0; i < 6; i++ {
color[i] = hashQuestion[rand.Intn(2)]
}
return "#" + replaceWithLetters(replaceWithNumbers(string(color)))
// color := ""
// for i := 1; i <= 6; i++ {
// color += RandString([]string{"?", "#"})
// }
/... | [
"func",
"HexColor",
"(",
")",
"string",
"{",
"color",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"6",
")",
"\n",
"hashQuestion",
":=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"6",
";",
"i",
"++",
"... | // HexColor will generate a random hexadecimal color string | [
"HexColor",
"will",
"generate",
"a",
"random",
"hexadecimal",
"color",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/color.go#L16-L39 |
26,945 | brianvoe/gofakeit | string.go | ShuffleStrings | func ShuffleStrings(a []string) {
swap := func(i, j int) {
a[i], a[j] = a[j], a[i]
}
//to avoid upgrading to 1.10 I copied the algorithm
n := len(a)
if n <= 1 {
return
}
//if size is > int32 probably it will never finish, or ran out of entropy
i := n - 1
for ; i > 0; i-- {
j := int(rand.Int31n(int32(i +... | go | func ShuffleStrings(a []string) {
swap := func(i, j int) {
a[i], a[j] = a[j], a[i]
}
//to avoid upgrading to 1.10 I copied the algorithm
n := len(a)
if n <= 1 {
return
}
//if size is > int32 probably it will never finish, or ran out of entropy
i := n - 1
for ; i > 0; i-- {
j := int(rand.Int31n(int32(i +... | [
"func",
"ShuffleStrings",
"(",
"a",
"[",
"]",
"string",
")",
"{",
"swap",
":=",
"func",
"(",
"i",
",",
"j",
"int",
")",
"{",
"a",
"[",
"i",
"]",
",",
"a",
"[",
"j",
"]",
"=",
"a",
"[",
"j",
"]",
",",
"a",
"[",
"i",
"]",
"\n",
"}",
"\n",... | // ShuffleStrings will randomize a slice of strings | [
"ShuffleStrings",
"will",
"randomize",
"a",
"slice",
"of",
"strings"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/string.go#L23-L39 |
26,946 | brianvoe/gofakeit | string.go | RandString | func RandString(a []string) string {
size := len(a)
if size == 0 {
return ""
}
return a[rand.Intn(size)]
} | go | func RandString(a []string) string {
size := len(a)
if size == 0 {
return ""
}
return a[rand.Intn(size)]
} | [
"func",
"RandString",
"(",
"a",
"[",
"]",
"string",
")",
"string",
"{",
"size",
":=",
"len",
"(",
"a",
")",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"a",
"[",
"rand",
".",
"Intn",
"(",
"size",
")",
... | // RandString will take in a slice of string and return a randomly selected value | [
"RandString",
"will",
"take",
"in",
"a",
"slice",
"of",
"string",
"and",
"return",
"a",
"randomly",
"selected",
"value"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/string.go#L42-L48 |
26,947 | brianvoe/gofakeit | vehicle.go | Vehicle | func Vehicle() *VehicleInfo {
return &VehicleInfo{
VehicleType: VehicleType(),
Fuel: FuelType(),
TransmissionGear: TransmissionGearType(),
Brand: CarMaker(),
Model: CarModel(),
Year: Year(),
}
} | go | func Vehicle() *VehicleInfo {
return &VehicleInfo{
VehicleType: VehicleType(),
Fuel: FuelType(),
TransmissionGear: TransmissionGearType(),
Brand: CarMaker(),
Model: CarModel(),
Year: Year(),
}
} | [
"func",
"Vehicle",
"(",
")",
"*",
"VehicleInfo",
"{",
"return",
"&",
"VehicleInfo",
"{",
"VehicleType",
":",
"VehicleType",
"(",
")",
",",
"Fuel",
":",
"FuelType",
"(",
")",
",",
"TransmissionGear",
":",
"TransmissionGearType",
"(",
")",
",",
"Brand",
":",... | // Vehicle will generate a struct with vehicle information | [
"Vehicle",
"will",
"generate",
"a",
"struct",
"with",
"vehicle",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/vehicle.go#L20-L30 |
26,948 | brianvoe/gofakeit | hipster.go | HipsterParagraph | func HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
return paragraphGenerator(paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, HipsterSentence)
} | go | func HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string {
return paragraphGenerator(paragrapOptions{paragraphCount, sentenceCount, wordCount, separator}, HipsterSentence)
} | [
"func",
"HipsterParagraph",
"(",
"paragraphCount",
"int",
",",
"sentenceCount",
"int",
",",
"wordCount",
"int",
",",
"separator",
"string",
")",
"string",
"{",
"return",
"paragraphGenerator",
"(",
"paragrapOptions",
"{",
"paragraphCount",
",",
"sentenceCount",
",",
... | // HipsterParagraph will generate a random paragraphGenerator
// Set Paragraph Count
// Set Sentence Count
// Set Word Count
// Set Paragraph Separator | [
"HipsterParagraph",
"will",
"generate",
"a",
"random",
"paragraphGenerator",
"Set",
"Paragraph",
"Count",
"Set",
"Sentence",
"Count",
"Set",
"Word",
"Count",
"Set",
"Paragraph",
"Separator"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/hipster.go#L18-L20 |
26,949 | brianvoe/gofakeit | hacker.go | HackerPhrase | func HackerPhrase() string {
words := strings.Split(Generate(getRandValue([]string{"hacker", "phrase"})), " ")
words[0] = strings.Title(words[0])
return strings.Join(words, " ")
} | go | func HackerPhrase() string {
words := strings.Split(Generate(getRandValue([]string{"hacker", "phrase"})), " ")
words[0] = strings.Title(words[0])
return strings.Join(words, " ")
} | [
"func",
"HackerPhrase",
"(",
")",
"string",
"{",
"words",
":=",
"strings",
".",
"Split",
"(",
"Generate",
"(",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"words",
"[",
"0"... | // HackerPhrase will return a random hacker sentence | [
"HackerPhrase",
"will",
"return",
"a",
"random",
"hacker",
"sentence"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/hacker.go#L6-L10 |
26,950 | brianvoe/gofakeit | number.go | ShuffleInts | func ShuffleInts(a []int) {
for i := range a {
j := rand.Intn(i + 1)
a[i], a[j] = a[j], a[i]
}
} | go | func ShuffleInts(a []int) {
for i := range a {
j := rand.Intn(i + 1)
a[i], a[j] = a[j], a[i]
}
} | [
"func",
"ShuffleInts",
"(",
"a",
"[",
"]",
"int",
")",
"{",
"for",
"i",
":=",
"range",
"a",
"{",
"j",
":=",
"rand",
".",
"Intn",
"(",
"i",
"+",
"1",
")",
"\n",
"a",
"[",
"i",
"]",
",",
"a",
"[",
"j",
"]",
"=",
"a",
"[",
"j",
"]",
",",
... | // ShuffleInts will randomize a slice of ints | [
"ShuffleInts",
"will",
"randomize",
"a",
"slice",
"of",
"ints"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/number.go#L79-L84 |
26,951 | brianvoe/gofakeit | job.go | Job | func Job() *JobInfo {
return &JobInfo{
Company: Company(),
Title: JobTitle(),
Descriptor: JobDescriptor(),
Level: JobLevel(),
}
} | go | func Job() *JobInfo {
return &JobInfo{
Company: Company(),
Title: JobTitle(),
Descriptor: JobDescriptor(),
Level: JobLevel(),
}
} | [
"func",
"Job",
"(",
")",
"*",
"JobInfo",
"{",
"return",
"&",
"JobInfo",
"{",
"Company",
":",
"Company",
"(",
")",
",",
"Title",
":",
"JobTitle",
"(",
")",
",",
"Descriptor",
":",
"JobDescriptor",
"(",
")",
",",
"Level",
":",
"JobLevel",
"(",
")",
"... | // Job will generate a struct with random job information | [
"Job",
"will",
"generate",
"a",
"struct",
"with",
"random",
"job",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/job.go#L12-L19 |
26,952 | brianvoe/gofakeit | contact.go | Email | func Email() string {
var email string
email = getRandValue([]string{"person", "first"}) + getRandValue([]string{"person", "last"})
email += "@"
email += getRandValue([]string{"person", "last"}) + "." + getRandValue([]string{"internet", "domain_suffix"})
return strings.ToLower(email)
} | go | func Email() string {
var email string
email = getRandValue([]string{"person", "first"}) + getRandValue([]string{"person", "last"})
email += "@"
email += getRandValue([]string{"person", "last"}) + "." + getRandValue([]string{"internet", "domain_suffix"})
return strings.ToLower(email)
} | [
"func",
"Email",
"(",
")",
"string",
"{",
"var",
"email",
"string",
"\n\n",
"email",
"=",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"+",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"... | // Email will generate a random email string | [
"Email",
"will",
"generate",
"a",
"random",
"email",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/contact.go#L32-L40 |
26,953 | brianvoe/gofakeit | person.go | Person | func Person() *PersonInfo {
return &PersonInfo{
FirstName: FirstName(),
LastName: LastName(),
Gender: Gender(),
SSN: SSN(),
Image: ImageURL(300, 300) + "/people",
Job: Job(),
Address: Address(),
Contact: Contact(),
CreditCard: CreditCard(),
}
} | go | func Person() *PersonInfo {
return &PersonInfo{
FirstName: FirstName(),
LastName: LastName(),
Gender: Gender(),
SSN: SSN(),
Image: ImageURL(300, 300) + "/people",
Job: Job(),
Address: Address(),
Contact: Contact(),
CreditCard: CreditCard(),
}
} | [
"func",
"Person",
"(",
")",
"*",
"PersonInfo",
"{",
"return",
"&",
"PersonInfo",
"{",
"FirstName",
":",
"FirstName",
"(",
")",
",",
"LastName",
":",
"LastName",
"(",
")",
",",
"Gender",
":",
"Gender",
"(",
")",
",",
"SSN",
":",
"SSN",
"(",
")",
","... | // Person will generate a struct with person information | [
"Person",
"will",
"generate",
"a",
"struct",
"with",
"person",
"information"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/person.go#L33-L45 |
26,954 | brianvoe/gofakeit | company.go | Company | func Company() (company string) {
switch randInt := randIntRange(1, 3); randInt {
case 1:
company = LastName() + ", " + LastName() + " and " + LastName()
case 2:
company = LastName() + "-" + LastName()
case 3:
company = LastName() + " " + CompanySuffix()
}
return
} | go | func Company() (company string) {
switch randInt := randIntRange(1, 3); randInt {
case 1:
company = LastName() + ", " + LastName() + " and " + LastName()
case 2:
company = LastName() + "-" + LastName()
case 3:
company = LastName() + " " + CompanySuffix()
}
return
} | [
"func",
"Company",
"(",
")",
"(",
"company",
"string",
")",
"{",
"switch",
"randInt",
":=",
"randIntRange",
"(",
"1",
",",
"3",
")",
";",
"randInt",
"{",
"case",
"1",
":",
"company",
"=",
"LastName",
"(",
")",
"+",
"\"",
"\"",
"+",
"LastName",
"(",... | // Company will generate a random company name string | [
"Company",
"will",
"generate",
"a",
"random",
"company",
"name",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/company.go#L4-L15 |
26,955 | brianvoe/gofakeit | datetime.go | Date | func Date() time.Time {
return time.Date(Year(), time.Month(Number(0, 12)), Day(), Hour(), Minute(), Second(), NanoSecond(), time.UTC)
} | go | func Date() time.Time {
return time.Date(Year(), time.Month(Number(0, 12)), Day(), Hour(), Minute(), Second(), NanoSecond(), time.UTC)
} | [
"func",
"Date",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Date",
"(",
"Year",
"(",
")",
",",
"time",
".",
"Month",
"(",
"Number",
"(",
"0",
",",
"12",
")",
")",
",",
"Day",
"(",
")",
",",
"Hour",
"(",
")",
",",
"Minute",
"... | // Date will generate a random time.Time struct | [
"Date",
"will",
"generate",
"a",
"random",
"time",
".",
"Time",
"struct"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/datetime.go#L9-L11 |
26,956 | brianvoe/gofakeit | datetime.go | DateRange | func DateRange(start, end time.Time) time.Time {
return time.Unix(0, int64(Number(int(start.UnixNano()), int(end.UnixNano())))).UTC()
} | go | func DateRange(start, end time.Time) time.Time {
return time.Unix(0, int64(Number(int(start.UnixNano()), int(end.UnixNano())))).UTC()
} | [
"func",
"DateRange",
"(",
"start",
",",
"end",
"time",
".",
"Time",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Unix",
"(",
"0",
",",
"int64",
"(",
"Number",
"(",
"int",
"(",
"start",
".",
"UnixNano",
"(",
")",
")",
",",
"int",
"(",
... | // DateRange will generate a random time.Time struct between a start and end date | [
"DateRange",
"will",
"generate",
"a",
"random",
"time",
".",
"Time",
"struct",
"between",
"a",
"start",
"and",
"end",
"date"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/datetime.go#L14-L16 |
26,957 | brianvoe/gofakeit | datetime.go | TimeZoneOffset | func TimeZoneOffset() float32 {
value, _ := strconv.ParseFloat(getRandValue([]string{"timezone", "offset"}), 32)
return float32(value)
} | go | func TimeZoneOffset() float32 {
value, _ := strconv.ParseFloat(getRandValue([]string{"timezone", "offset"}), 32)
return float32(value)
} | [
"func",
"TimeZoneOffset",
"(",
")",
"float32",
"{",
"value",
",",
"_",
":=",
"strconv",
".",
"ParseFloat",
"(",
"getRandValue",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
",",
"32",
")",
"\n",
"return",
"float32",
"(",
"va... | // TimeZoneOffset will select a random timezone offset | [
"TimeZoneOffset",
"will",
"select",
"a",
"random",
"timezone",
"offset"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/datetime.go#L74-L77 |
26,958 | brianvoe/gofakeit | internet.go | URL | func URL() string {
url := "http" + RandString([]string{"s", ""}) + "://www."
url += DomainName()
// Slugs
num := Number(1, 4)
slug := make([]string, num)
for i := 0; i < num; i++ {
slug[i] = BS()
}
url += "/" + strings.ToLower(strings.Join(slug, "/"))
return url
} | go | func URL() string {
url := "http" + RandString([]string{"s", ""}) + "://www."
url += DomainName()
// Slugs
num := Number(1, 4)
slug := make([]string, num)
for i := 0; i < num; i++ {
slug[i] = BS()
}
url += "/" + strings.ToLower(strings.Join(slug, "/"))
return url
} | [
"func",
"URL",
"(",
")",
"string",
"{",
"url",
":=",
"\"",
"\"",
"+",
"RandString",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"+",
"\"",
"\"",
"\n",
"url",
"+=",
"DomainName",
"(",
")",
"\n\n",
"// Slugs",
"num",
":="... | // URL will generate a random url string | [
"URL",
"will",
"generate",
"a",
"random",
"url",
"string"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/internet.go#L20-L33 |
26,959 | brianvoe/gofakeit | internet.go | IPv4Address | func IPv4Address() string {
num := func() int { return 2 + rand.Intn(254) }
return fmt.Sprintf("%d.%d.%d.%d", num(), num(), num(), num())
} | go | func IPv4Address() string {
num := func() int { return 2 + rand.Intn(254) }
return fmt.Sprintf("%d.%d.%d.%d", num(), num(), num(), num())
} | [
"func",
"IPv4Address",
"(",
")",
"string",
"{",
"num",
":=",
"func",
"(",
")",
"int",
"{",
"return",
"2",
"+",
"rand",
".",
"Intn",
"(",
"254",
")",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"num",
"(",
")",
",",
"num",
... | // IPv4Address will generate a random version 4 ip address | [
"IPv4Address",
"will",
"generate",
"a",
"random",
"version",
"4",
"ip",
"address"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/internet.go#L41-L44 |
26,960 | brianvoe/gofakeit | internet.go | IPv6Address | func IPv6Address() string {
num := 65536
return fmt.Sprintf("2001:cafe:%x:%x:%x:%x:%x:%x", rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num))
} | go | func IPv6Address() string {
num := 65536
return fmt.Sprintf("2001:cafe:%x:%x:%x:%x:%x:%x", rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num), rand.Intn(num))
} | [
"func",
"IPv6Address",
"(",
")",
"string",
"{",
"num",
":=",
"65536",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"rand",
".",
"Intn",
"(",
"num",
")",
",",
"rand",
".",
"Intn",
"(",
"num",
")",
",",
"rand",
".",
"Intn",
"(",
"... | // IPv6Address will generate a random version 6 ip address | [
"IPv6Address",
"will",
"generate",
"a",
"random",
"version",
"6",
"ip",
"address"
] | a5ac7cef41d64b726c51e8826e02dad0c34f55b4 | https://github.com/brianvoe/gofakeit/blob/a5ac7cef41d64b726c51e8826e02dad0c34f55b4/internet.go#L47-L50 |
26,961 | gorilla/handlers | cors.go | AllowedMethods | func AllowedMethods(methods []string) CORSOption {
return func(ch *cors) error {
ch.allowedMethods = []string{}
for _, v := range methods {
normalizedMethod := strings.ToUpper(strings.TrimSpace(v))
if normalizedMethod == "" {
continue
}
if !ch.isMatch(normalizedMethod, ch.allowedMethods) {
ch.... | go | func AllowedMethods(methods []string) CORSOption {
return func(ch *cors) error {
ch.allowedMethods = []string{}
for _, v := range methods {
normalizedMethod := strings.ToUpper(strings.TrimSpace(v))
if normalizedMethod == "" {
continue
}
if !ch.isMatch(normalizedMethod, ch.allowedMethods) {
ch.... | [
"func",
"AllowedMethods",
"(",
"methods",
"[",
"]",
"string",
")",
"CORSOption",
"{",
"return",
"func",
"(",
"ch",
"*",
"cors",
")",
"error",
"{",
"ch",
".",
"allowedMethods",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"ra... | // AllowedMethods can be used to explicitly allow methods in the
// Access-Control-Allow-Methods header.
// This is a replacement operation so you must also
// pass GET, HEAD, and POST if you wish to support those methods. | [
"AllowedMethods",
"can",
"be",
"used",
"to",
"explicitly",
"allow",
"methods",
"in",
"the",
"Access",
"-",
"Control",
"-",
"Allow",
"-",
"Methods",
"header",
".",
"This",
"is",
"a",
"replacement",
"operation",
"so",
"you",
"must",
"also",
"pass",
"GET",
"H... | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/cors.go#L214-L230 |
26,962 | gorilla/handlers | cors.go | AllowedOriginValidator | func AllowedOriginValidator(fn OriginValidator) CORSOption {
return func(ch *cors) error {
ch.allowedOriginValidator = fn
return nil
}
} | go | func AllowedOriginValidator(fn OriginValidator) CORSOption {
return func(ch *cors) error {
ch.allowedOriginValidator = fn
return nil
}
} | [
"func",
"AllowedOriginValidator",
"(",
"fn",
"OriginValidator",
")",
"CORSOption",
"{",
"return",
"func",
"(",
"ch",
"*",
"cors",
")",
"error",
"{",
"ch",
".",
"allowedOriginValidator",
"=",
"fn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // AllowedOriginValidator sets a function for evaluating allowed origins in CORS requests, represented by the
// 'Allow-Access-Control-Origin' HTTP header. | [
"AllowedOriginValidator",
"sets",
"a",
"function",
"for",
"evaluating",
"allowed",
"origins",
"in",
"CORS",
"requests",
"represented",
"by",
"the",
"Allow",
"-",
"Access",
"-",
"Control",
"-",
"Origin",
"HTTP",
"header",
"."
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/cors.go#L251-L256 |
26,963 | gorilla/handlers | cors.go | ExposedHeaders | func ExposedHeaders(headers []string) CORSOption {
return func(ch *cors) error {
ch.exposedHeaders = []string{}
for _, v := range headers {
normalizedHeader := http.CanonicalHeaderKey(strings.TrimSpace(v))
if normalizedHeader == "" {
continue
}
if !ch.isMatch(normalizedHeader, ch.exposedHeaders) {... | go | func ExposedHeaders(headers []string) CORSOption {
return func(ch *cors) error {
ch.exposedHeaders = []string{}
for _, v := range headers {
normalizedHeader := http.CanonicalHeaderKey(strings.TrimSpace(v))
if normalizedHeader == "" {
continue
}
if !ch.isMatch(normalizedHeader, ch.exposedHeaders) {... | [
"func",
"ExposedHeaders",
"(",
"headers",
"[",
"]",
"string",
")",
"CORSOption",
"{",
"return",
"func",
"(",
"ch",
"*",
"cors",
")",
"error",
"{",
"ch",
".",
"exposedHeaders",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"ra... | // ExposedHeaders can be used to specify headers that are available
// and will not be stripped out by the user-agent. | [
"ExposedHeaders",
"can",
"be",
"used",
"to",
"specify",
"headers",
"that",
"are",
"available",
"and",
"will",
"not",
"be",
"stripped",
"out",
"by",
"the",
"user",
"-",
"agent",
"."
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/cors.go#L273-L289 |
26,964 | gorilla/handlers | logging.go | buildCommonLogLine | func buildCommonLogLine(req *http.Request, url url.URL, ts time.Time, status int, size int) []byte {
username := "-"
if url.User != nil {
if name := url.User.Username(); name != "" {
username = name
}
}
host, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
host = req.RemoteAddr
}
uri := r... | go | func buildCommonLogLine(req *http.Request, url url.URL, ts time.Time, status int, size int) []byte {
username := "-"
if url.User != nil {
if name := url.User.Username(); name != "" {
username = name
}
}
host, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
host = req.RemoteAddr
}
uri := r... | [
"func",
"buildCommonLogLine",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"url",
"url",
".",
"URL",
",",
"ts",
"time",
".",
"Time",
",",
"status",
"int",
",",
"size",
"int",
")",
"[",
"]",
"byte",
"{",
"username",
":=",
"\"",
"\"",
"\n",
"if",
... | // buildCommonLogLine builds a log entry for req in Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status and size are used to provide the response HTTP status and size. | [
"buildCommonLogLine",
"builds",
"a",
"log",
"entry",
"for",
"req",
"in",
"Apache",
"Common",
"Log",
"Format",
".",
"ts",
"is",
"the",
"timestamp",
"with",
"which",
"the",
"entry",
"should",
"be",
"logged",
".",
"status",
"and",
"size",
"are",
"used",
"to",... | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/logging.go#L151-L194 |
26,965 | gorilla/handlers | logging.go | writeLog | func writeLog(writer io.Writer, params LogFormatterParams) {
buf := buildCommonLogLine(params.Request, params.URL, params.TimeStamp, params.StatusCode, params.Size)
buf = append(buf, '\n')
writer.Write(buf)
} | go | func writeLog(writer io.Writer, params LogFormatterParams) {
buf := buildCommonLogLine(params.Request, params.URL, params.TimeStamp, params.StatusCode, params.Size)
buf = append(buf, '\n')
writer.Write(buf)
} | [
"func",
"writeLog",
"(",
"writer",
"io",
".",
"Writer",
",",
"params",
"LogFormatterParams",
")",
"{",
"buf",
":=",
"buildCommonLogLine",
"(",
"params",
".",
"Request",
",",
"params",
".",
"URL",
",",
"params",
".",
"TimeStamp",
",",
"params",
".",
"Status... | // writeLog writes a log entry for req to w in Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status and size are used to provide the response HTTP status and size. | [
"writeLog",
"writes",
"a",
"log",
"entry",
"for",
"req",
"to",
"w",
"in",
"Apache",
"Common",
"Log",
"Format",
".",
"ts",
"is",
"the",
"timestamp",
"with",
"which",
"the",
"entry",
"should",
"be",
"logged",
".",
"status",
"and",
"size",
"are",
"used",
... | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/logging.go#L199-L203 |
26,966 | gorilla/handlers | logging.go | writeCombinedLog | func writeCombinedLog(writer io.Writer, params LogFormatterParams) {
buf := buildCommonLogLine(params.Request, params.URL, params.TimeStamp, params.StatusCode, params.Size)
buf = append(buf, ` "`...)
buf = appendQuoted(buf, params.Request.Referer())
buf = append(buf, `" "`...)
buf = appendQuoted(buf, params.Reques... | go | func writeCombinedLog(writer io.Writer, params LogFormatterParams) {
buf := buildCommonLogLine(params.Request, params.URL, params.TimeStamp, params.StatusCode, params.Size)
buf = append(buf, ` "`...)
buf = appendQuoted(buf, params.Request.Referer())
buf = append(buf, `" "`...)
buf = appendQuoted(buf, params.Reques... | [
"func",
"writeCombinedLog",
"(",
"writer",
"io",
".",
"Writer",
",",
"params",
"LogFormatterParams",
")",
"{",
"buf",
":=",
"buildCommonLogLine",
"(",
"params",
".",
"Request",
",",
"params",
".",
"URL",
",",
"params",
".",
"TimeStamp",
",",
"params",
".",
... | // writeCombinedLog writes a log entry for req to w in Apache Combined Log Format.
// ts is the timestamp with which the entry should be logged.
// status and size are used to provide the response HTTP status and size. | [
"writeCombinedLog",
"writes",
"a",
"log",
"entry",
"for",
"req",
"to",
"w",
"in",
"Apache",
"Combined",
"Log",
"Format",
".",
"ts",
"is",
"the",
"timestamp",
"with",
"which",
"the",
"entry",
"should",
"be",
"logged",
".",
"status",
"and",
"size",
"are",
... | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/logging.go#L208-L216 |
26,967 | gorilla/handlers | logging.go | CustomLoggingHandler | func CustomLoggingHandler(out io.Writer, h http.Handler, f LogFormatter) http.Handler {
return loggingHandler{out, h, f}
} | go | func CustomLoggingHandler(out io.Writer, h http.Handler, f LogFormatter) http.Handler {
return loggingHandler{out, h, f}
} | [
"func",
"CustomLoggingHandler",
"(",
"out",
"io",
".",
"Writer",
",",
"h",
"http",
".",
"Handler",
",",
"f",
"LogFormatter",
")",
"http",
".",
"Handler",
"{",
"return",
"loggingHandler",
"{",
"out",
",",
"h",
",",
"f",
"}",
"\n",
"}"
] | // CustomLoggingHandler provides a way to supply a custom log formatter
// while taking advantage of the mechanisms in this package | [
"CustomLoggingHandler",
"provides",
"a",
"way",
"to",
"supply",
"a",
"custom",
"log",
"formatter",
"while",
"taking",
"advantage",
"of",
"the",
"mechanisms",
"in",
"this",
"package"
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/logging.go#L250-L252 |
26,968 | gorilla/handlers | handlers.go | isContentType | func isContentType(h http.Header, contentType string) bool {
ct := h.Get("Content-Type")
if i := strings.IndexRune(ct, ';'); i != -1 {
ct = ct[0:i]
}
return ct == contentType
} | go | func isContentType(h http.Header, contentType string) bool {
ct := h.Get("Content-Type")
if i := strings.IndexRune(ct, ';'); i != -1 {
ct = ct[0:i]
}
return ct == contentType
} | [
"func",
"isContentType",
"(",
"h",
"http",
".",
"Header",
",",
"contentType",
"string",
")",
"bool",
"{",
"ct",
":=",
"h",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"i",
":=",
"strings",
".",
"IndexRune",
"(",
"ct",
",",
"';'",
")",
";",
"i",... | // isContentType validates the Content-Type header matches the supplied
// contentType. That is, its type and subtype match. | [
"isContentType",
"validates",
"the",
"Content",
"-",
"Type",
"header",
"matches",
"the",
"supplied",
"contentType",
".",
"That",
"is",
"its",
"type",
"and",
"subtype",
"match",
"."
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/handlers.go#L112-L118 |
26,969 | gorilla/handlers | handlers.go | ContentTypeHandler | func ContentTypeHandler(h http.Handler, contentTypes ...string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !(r.Method == "PUT" || r.Method == "POST" || r.Method == "PATCH") {
h.ServeHTTP(w, r)
return
}
for _, ct := range contentTypes {
if isContentType(r.He... | go | func ContentTypeHandler(h http.Handler, contentTypes ...string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !(r.Method == "PUT" || r.Method == "POST" || r.Method == "PATCH") {
h.ServeHTTP(w, r)
return
}
for _, ct := range contentTypes {
if isContentType(r.He... | [
"func",
"ContentTypeHandler",
"(",
"h",
"http",
".",
"Handler",
",",
"contentTypes",
"...",
"string",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
"."... | // ContentTypeHandler wraps and returns a http.Handler, validating the request
// content type is compatible with the contentTypes list. It writes a HTTP 415
// error if that fails.
//
// Only PUT, POST, and PATCH requests are considered. | [
"ContentTypeHandler",
"wraps",
"and",
"returns",
"a",
"http",
".",
"Handler",
"validating",
"the",
"request",
"content",
"type",
"is",
"compatible",
"with",
"the",
"contentTypes",
"list",
".",
"It",
"writes",
"a",
"HTTP",
"415",
"error",
"if",
"that",
"fails",... | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/handlers.go#L125-L140 |
26,970 | gorilla/handlers | recovery.go | RecoveryLogger | func RecoveryLogger(logger RecoveryHandlerLogger) RecoveryOption {
return func(h http.Handler) {
r := h.(*recoveryHandler)
r.logger = logger
}
} | go | func RecoveryLogger(logger RecoveryHandlerLogger) RecoveryOption {
return func(h http.Handler) {
r := h.(*recoveryHandler)
r.logger = logger
}
} | [
"func",
"RecoveryLogger",
"(",
"logger",
"RecoveryHandlerLogger",
")",
"RecoveryOption",
"{",
"return",
"func",
"(",
"h",
"http",
".",
"Handler",
")",
"{",
"r",
":=",
"h",
".",
"(",
"*",
"recoveryHandler",
")",
"\n",
"r",
".",
"logger",
"=",
"logger",
"\... | // RecoveryLogger is a functional option to override
// the default logger | [
"RecoveryLogger",
"is",
"a",
"functional",
"option",
"to",
"override",
"the",
"default",
"logger"
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/recovery.go#L54-L59 |
26,971 | gorilla/handlers | recovery.go | PrintRecoveryStack | func PrintRecoveryStack(print bool) RecoveryOption {
return func(h http.Handler) {
r := h.(*recoveryHandler)
r.printStack = print
}
} | go | func PrintRecoveryStack(print bool) RecoveryOption {
return func(h http.Handler) {
r := h.(*recoveryHandler)
r.printStack = print
}
} | [
"func",
"PrintRecoveryStack",
"(",
"print",
"bool",
")",
"RecoveryOption",
"{",
"return",
"func",
"(",
"h",
"http",
".",
"Handler",
")",
"{",
"r",
":=",
"h",
".",
"(",
"*",
"recoveryHandler",
")",
"\n",
"r",
".",
"printStack",
"=",
"print",
"\n",
"}",
... | // PrintRecoveryStack is a functional option to enable
// or disable printing stack traces on panic. | [
"PrintRecoveryStack",
"is",
"a",
"functional",
"option",
"to",
"enable",
"or",
"disable",
"printing",
"stack",
"traces",
"on",
"panic",
"."
] | ac6d24f88de4584385a0cb3a88f953d08a2f7a05 | https://github.com/gorilla/handlers/blob/ac6d24f88de4584385a0cb3a88f953d08a2f7a05/recovery.go#L63-L68 |
26,972 | colinmarc/hdfs | internal/rpc/block_writer.go | SetDeadline | func (bw *BlockWriter) SetDeadline(t time.Time) error {
bw.deadline = t
if bw.conn != nil {
return bw.conn.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | go | func (bw *BlockWriter) SetDeadline(t time.Time) error {
bw.deadline = t
if bw.conn != nil {
return bw.conn.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | [
"func",
"(",
"bw",
"*",
"BlockWriter",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"bw",
".",
"deadline",
"=",
"t",
"\n",
"if",
"bw",
".",
"conn",
"!=",
"nil",
"{",
"return",
"bw",
".",
"conn",
".",
"SetDeadline",
"(",
"... | // SetDeadline sets the deadline for future Write, Flush, and Close calls. A
// zero value for t means those calls will not time out. | [
"SetDeadline",
"sets",
"the",
"deadline",
"for",
"future",
"Write",
"Flush",
"and",
"Close",
"calls",
".",
"A",
"zero",
"value",
"for",
"t",
"means",
"those",
"calls",
"will",
"not",
"time",
"out",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_writer.go#L49-L57 |
26,973 | colinmarc/hdfs | internal/rpc/block_writer.go | Flush | func (bw *BlockWriter) Flush() error {
if bw.stream != nil {
return bw.stream.flush(true)
}
return nil
} | go | func (bw *BlockWriter) Flush() error {
if bw.stream != nil {
return bw.stream.flush(true)
}
return nil
} | [
"func",
"(",
"bw",
"*",
"BlockWriter",
")",
"Flush",
"(",
")",
"error",
"{",
"if",
"bw",
".",
"stream",
"!=",
"nil",
"{",
"return",
"bw",
".",
"stream",
".",
"flush",
"(",
"true",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Flush flushes any unwritten packets out to the datanode. | [
"Flush",
"flushes",
"any",
"unwritten",
"packets",
"out",
"to",
"the",
"datanode",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_writer.go#L94-L100 |
26,974 | colinmarc/hdfs | internal/rpc/block_writer.go | Close | func (bw *BlockWriter) Close() error {
bw.closed = true
if bw.conn != nil {
defer bw.conn.Close()
}
if bw.stream != nil {
// TODO: handle failures, set up recovery pipeline
err := bw.stream.finish()
if err != nil {
return err
}
}
return nil
} | go | func (bw *BlockWriter) Close() error {
bw.closed = true
if bw.conn != nil {
defer bw.conn.Close()
}
if bw.stream != nil {
// TODO: handle failures, set up recovery pipeline
err := bw.stream.finish()
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"bw",
"*",
"BlockWriter",
")",
"Close",
"(",
")",
"error",
"{",
"bw",
".",
"closed",
"=",
"true",
"\n",
"if",
"bw",
".",
"conn",
"!=",
"nil",
"{",
"defer",
"bw",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"bw",
... | // Close implements io.Closer. It flushes any unwritten packets out to the
// datanode, and sends a final packet indicating the end of the block. The
// block must still be finalized with the namenode. | [
"Close",
"implements",
"io",
".",
"Closer",
".",
"It",
"flushes",
"any",
"unwritten",
"packets",
"out",
"to",
"the",
"datanode",
"and",
"sends",
"a",
"final",
"packet",
"indicating",
"the",
"end",
"of",
"the",
"block",
".",
"The",
"block",
"must",
"still",... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_writer.go#L105-L120 |
26,975 | colinmarc/hdfs | internal/rpc/namenode.go | NewNamenodeConnection | func NewNamenodeConnection(options NamenodeConnectionOptions) (*NamenodeConnection, error) {
// Build the list of hosts to be used for failover.
hostList := make([]*namenodeHost, len(options.Addresses))
for i, addr := range options.Addresses {
hostList[i] = &namenodeHost{address: addr}
}
var user, realm string
... | go | func NewNamenodeConnection(options NamenodeConnectionOptions) (*NamenodeConnection, error) {
// Build the list of hosts to be used for failover.
hostList := make([]*namenodeHost, len(options.Addresses))
for i, addr := range options.Addresses {
hostList[i] = &namenodeHost{address: addr}
}
var user, realm string
... | [
"func",
"NewNamenodeConnection",
"(",
"options",
"NamenodeConnectionOptions",
")",
"(",
"*",
"NamenodeConnection",
",",
"error",
")",
"{",
"// Build the list of hosts to be used for failover.",
"hostList",
":=",
"make",
"(",
"[",
"]",
"*",
"namenodeHost",
",",
"len",
... | // NewNamenodeConnectionWithOptions creates a new connection to a namenode with
// the given options and performs an initial handshake. | [
"NewNamenodeConnectionWithOptions",
"creates",
"a",
"new",
"connection",
"to",
"a",
"namenode",
"with",
"the",
"given",
"options",
"and",
"performs",
"an",
"initial",
"handshake",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/namenode.go#L82-L123 |
26,976 | colinmarc/hdfs | internal/rpc/namenode.go | Execute | func (c *NamenodeConnection) Execute(method string, req proto.Message, resp proto.Message) error {
c.reqLock.Lock()
defer c.reqLock.Unlock()
c.currentRequestID++
for {
err := c.resolveConnection()
if err != nil {
return err
}
err = c.writeRequest(method, req)
if err != nil {
c.markFailure(err)
... | go | func (c *NamenodeConnection) Execute(method string, req proto.Message, resp proto.Message) error {
c.reqLock.Lock()
defer c.reqLock.Unlock()
c.currentRequestID++
for {
err := c.resolveConnection()
if err != nil {
return err
}
err = c.writeRequest(method, req)
if err != nil {
c.markFailure(err)
... | [
"func",
"(",
"c",
"*",
"NamenodeConnection",
")",
"Execute",
"(",
"method",
"string",
",",
"req",
"proto",
".",
"Message",
",",
"resp",
"proto",
".",
"Message",
")",
"error",
"{",
"c",
".",
"reqLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
... | // Execute performs an rpc call. It does this by sending req over the wire and
// unmarshaling the result into resp. | [
"Execute",
"performs",
"an",
"rpc",
"call",
".",
"It",
"does",
"this",
"by",
"sending",
"req",
"over",
"the",
"wire",
"and",
"unmarshaling",
"the",
"result",
"into",
"resp",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/namenode.go#L178-L211 |
26,977 | colinmarc/hdfs | internal/rpc/namenode.go | Close | func (c *NamenodeConnection) Close() error {
if c.conn != nil {
return c.conn.Close()
}
return nil
} | go | func (c *NamenodeConnection) Close() error {
if c.conn != nil {
return c.conn.Close()
}
return nil
} | [
"func",
"(",
"c",
"*",
"NamenodeConnection",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"c",
".",
"conn",
"!=",
"nil",
"{",
"return",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Close terminates all underlying socket connections to remote server. | [
"Close",
"terminates",
"all",
"underlying",
"socket",
"connections",
"to",
"remote",
"server",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/namenode.go#L326-L331 |
26,978 | colinmarc/hdfs | file_reader.go | Open | func (c *Client) Open(name string) (*FileReader, error) {
info, err := c.getFileInfo(name)
if err != nil {
return nil, &os.PathError{"open", name, interpretException(err)}
}
return &FileReader{
client: c,
name: name,
info: info,
closed: false,
}, nil
} | go | func (c *Client) Open(name string) (*FileReader, error) {
info, err := c.getFileInfo(name)
if err != nil {
return nil, &os.PathError{"open", name, interpretException(err)}
}
return &FileReader{
client: c,
name: name,
info: info,
closed: false,
}, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"*",
"FileReader",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"c",
".",
"getFileInfo",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // Open returns an FileReader which can be used for reading. | [
"Open",
"returns",
"an",
"FileReader",
"which",
"can",
"be",
"used",
"for",
"reading",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_reader.go#L35-L47 |
26,979 | colinmarc/hdfs | file_reader.go | SetDeadline | func (f *FileReader) SetDeadline(t time.Time) error {
f.deadline = t
if f.blockReader != nil {
return f.blockReader.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | go | func (f *FileReader) SetDeadline(t time.Time) error {
f.deadline = t
if f.blockReader != nil {
return f.blockReader.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | [
"func",
"(",
"f",
"*",
"FileReader",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"f",
".",
"deadline",
"=",
"t",
"\n",
"if",
"f",
".",
"blockReader",
"!=",
"nil",
"{",
"return",
"f",
".",
"blockReader",
".",
"SetDeadline",
... | // SetDeadline sets the deadline for future Read, ReadAt, and Checksum calls. A
// zero value for t means those calls will not time out. | [
"SetDeadline",
"sets",
"the",
"deadline",
"for",
"future",
"Read",
"ReadAt",
"and",
"Checksum",
"calls",
".",
"A",
"zero",
"value",
"for",
"t",
"means",
"those",
"calls",
"will",
"not",
"time",
"out",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_reader.go#L61-L69 |
26,980 | colinmarc/hdfs | file_reader.go | Seek | func (f *FileReader) Seek(offset int64, whence int) (int64, error) {
if f.closed {
return 0, io.ErrClosedPipe
}
var off int64
if whence == 0 {
off = offset
} else if whence == 1 {
off = f.offset + offset
} else if whence == 2 {
off = f.info.Size() + offset
} else {
return f.offset, fmt.Errorf("invalid... | go | func (f *FileReader) Seek(offset int64, whence int) (int64, error) {
if f.closed {
return 0, io.ErrClosedPipe
}
var off int64
if whence == 0 {
off = offset
} else if whence == 1 {
off = f.offset + offset
} else if whence == 2 {
off = f.info.Size() + offset
} else {
return f.offset, fmt.Errorf("invalid... | [
"func",
"(",
"f",
"*",
"FileReader",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"f",
".",
"closed",
"{",
"return",
"0",
",",
"io",
".",
"ErrClosedPipe",
"\n",
"}",
"\n\n",
"var",
"o... | // Seek implements io.Seeker.
//
// The seek is virtual - it starts a new block read at the new position. | [
"Seek",
"implements",
"io",
".",
"Seeker",
".",
"The",
"seek",
"is",
"virtual",
"-",
"it",
"starts",
"a",
"new",
"block",
"read",
"at",
"the",
"new",
"position",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_reader.go#L131-L159 |
26,981 | colinmarc/hdfs | file_writer.go | CreateFile | func (c *Client) CreateFile(name string, replication int, blockSize int64, perm os.FileMode) (*FileWriter, error) {
createReq := &hdfs.CreateRequestProto{
Src: proto.String(name),
Masked: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
ClientName: proto.String(c.namenode.ClientName),
... | go | func (c *Client) CreateFile(name string, replication int, blockSize int64, perm os.FileMode) (*FileWriter, error) {
createReq := &hdfs.CreateRequestProto{
Src: proto.String(name),
Masked: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
ClientName: proto.String(c.namenode.ClientName),
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateFile",
"(",
"name",
"string",
",",
"replication",
"int",
",",
"blockSize",
"int64",
",",
"perm",
"os",
".",
"FileMode",
")",
"(",
"*",
"FileWriter",
",",
"error",
")",
"{",
"createReq",
":=",
"&",
"hdfs",
... | // CreateFile opens a new file in HDFS with the given replication, block size,
// and permissions, and returns an io.WriteCloser for writing to it. Because of
// the way that HDFS writes are buffered and acknowledged asynchronously, it is
// very important that Close is called after all data has been written. | [
"CreateFile",
"opens",
"a",
"new",
"file",
"in",
"HDFS",
"with",
"the",
"given",
"replication",
"block",
"size",
"and",
"permissions",
"and",
"returns",
"an",
"io",
".",
"WriteCloser",
"for",
"writing",
"to",
"it",
".",
"Because",
"of",
"the",
"way",
"that... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L55-L78 |
26,982 | colinmarc/hdfs | file_writer.go | Append | func (c *Client) Append(name string) (*FileWriter, error) {
_, err := c.getFileInfo(name)
if err != nil {
return nil, &os.PathError{"append", name, interpretException(err)}
}
appendReq := &hdfs.AppendRequestProto{
Src: proto.String(name),
ClientName: proto.String(c.namenode.ClientName),
}
appendResp... | go | func (c *Client) Append(name string) (*FileWriter, error) {
_, err := c.getFileInfo(name)
if err != nil {
return nil, &os.PathError{"append", name, interpretException(err)}
}
appendReq := &hdfs.AppendRequestProto{
Src: proto.String(name),
ClientName: proto.String(c.namenode.ClientName),
}
appendResp... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Append",
"(",
"name",
"string",
")",
"(",
"*",
"FileWriter",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"c",
".",
"getFileInfo",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // Append opens an existing file in HDFS and returns an io.WriteCloser for
// writing to it. Because of the way that HDFS writes are buffered and
// acknowledged asynchronously, it is very important that Close is called after
// all data has been written. | [
"Append",
"opens",
"an",
"existing",
"file",
"in",
"HDFS",
"and",
"returns",
"an",
"io",
".",
"WriteCloser",
"for",
"writing",
"to",
"it",
".",
"Because",
"of",
"the",
"way",
"that",
"HDFS",
"writes",
"are",
"buffered",
"and",
"acknowledged",
"asynchronously... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L84-L131 |
26,983 | colinmarc/hdfs | file_writer.go | CreateEmptyFile | func (c *Client) CreateEmptyFile(name string) error {
f, err := c.Create(name)
if err != nil {
return err
}
return f.Close()
} | go | func (c *Client) CreateEmptyFile(name string) error {
f, err := c.Create(name)
if err != nil {
return err
}
return f.Close()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateEmptyFile",
"(",
"name",
"string",
")",
"error",
"{",
"f",
",",
"err",
":=",
"c",
".",
"Create",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"f"... | // CreateEmptyFile creates a empty file at the given name, with the
// permissions 0644. | [
"CreateEmptyFile",
"creates",
"a",
"empty",
"file",
"at",
"the",
"given",
"name",
"with",
"the",
"permissions",
"0644",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L135-L142 |
26,984 | colinmarc/hdfs | file_writer.go | SetDeadline | func (f *FileWriter) SetDeadline(t time.Time) error {
f.deadline = t
if f.blockWriter != nil {
return f.blockWriter.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | go | func (f *FileWriter) SetDeadline(t time.Time) error {
f.deadline = t
if f.blockWriter != nil {
return f.blockWriter.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | [
"func",
"(",
"f",
"*",
"FileWriter",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"f",
".",
"deadline",
"=",
"t",
"\n",
"if",
"f",
".",
"blockWriter",
"!=",
"nil",
"{",
"return",
"f",
".",
"blockWriter",
".",
"SetDeadline",
... | // SetDeadline sets the deadline for future Write, Flush, and Close calls. A
// zero value for t means those calls will not time out.
//
// Note that because of buffering, Write calls that do not result in a blocking
// network call may still succeed after the deadline. | [
"SetDeadline",
"sets",
"the",
"deadline",
"for",
"future",
"Write",
"Flush",
"and",
"Close",
"calls",
".",
"A",
"zero",
"value",
"for",
"t",
"means",
"those",
"calls",
"will",
"not",
"time",
"out",
".",
"Note",
"that",
"because",
"of",
"buffering",
"Write"... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L149-L157 |
26,985 | colinmarc/hdfs | file_writer.go | Write | func (f *FileWriter) Write(b []byte) (int, error) {
if f.closed {
return 0, io.ErrClosedPipe
}
if f.blockWriter == nil {
err := f.startNewBlock()
if err != nil {
return 0, err
}
}
off := 0
for off < len(b) {
n, err := f.blockWriter.Write(b[off:])
off += n
if err == rpc.ErrEndOfBlock {
err = ... | go | func (f *FileWriter) Write(b []byte) (int, error) {
if f.closed {
return 0, io.ErrClosedPipe
}
if f.blockWriter == nil {
err := f.startNewBlock()
if err != nil {
return 0, err
}
}
off := 0
for off < len(b) {
n, err := f.blockWriter.Write(b[off:])
off += n
if err == rpc.ErrEndOfBlock {
err = ... | [
"func",
"(",
"f",
"*",
"FileWriter",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"f",
".",
"closed",
"{",
"return",
"0",
",",
"io",
".",
"ErrClosedPipe",
"\n",
"}",
"\n\n",
"if",
"f",
".",
"blockWrit... | // Write implements io.Writer for writing to a file in HDFS. Internally, it
// writes data to an internal buffer first, and then later out to HDFS. Because
// of this, it is important that Close is called after all data has been
// written. | [
"Write",
"implements",
"io",
".",
"Writer",
"for",
"writing",
"to",
"a",
"file",
"in",
"HDFS",
".",
"Internally",
"it",
"writes",
"data",
"to",
"an",
"internal",
"buffer",
"first",
"and",
"then",
"later",
"out",
"to",
"HDFS",
".",
"Because",
"of",
"this"... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L163-L189 |
26,986 | colinmarc/hdfs | file_writer.go | Flush | func (f *FileWriter) Flush() error {
if f.closed {
return io.ErrClosedPipe
}
if f.blockWriter != nil {
return f.blockWriter.Flush()
}
return nil
} | go | func (f *FileWriter) Flush() error {
if f.closed {
return io.ErrClosedPipe
}
if f.blockWriter != nil {
return f.blockWriter.Flush()
}
return nil
} | [
"func",
"(",
"f",
"*",
"FileWriter",
")",
"Flush",
"(",
")",
"error",
"{",
"if",
"f",
".",
"closed",
"{",
"return",
"io",
".",
"ErrClosedPipe",
"\n",
"}",
"\n\n",
"if",
"f",
".",
"blockWriter",
"!=",
"nil",
"{",
"return",
"f",
".",
"blockWriter",
"... | // Flush flushes any buffered data out to the datanodes. Even immediately after
// a call to Flush, it is still necessary to call Close once all data has been
// written. | [
"Flush",
"flushes",
"any",
"buffered",
"data",
"out",
"to",
"the",
"datanodes",
".",
"Even",
"immediately",
"after",
"a",
"call",
"to",
"Flush",
"it",
"is",
"still",
"necessary",
"to",
"call",
"Close",
"once",
"all",
"data",
"has",
"been",
"written",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L194-L204 |
26,987 | colinmarc/hdfs | file_writer.go | Close | func (f *FileWriter) Close() error {
if f.closed {
return io.ErrClosedPipe
}
var lastBlock *hdfs.ExtendedBlockProto
if f.blockWriter != nil {
lastBlock = f.blockWriter.Block.GetB()
// Close the blockWriter, flushing any buffered packets.
err := f.finalizeBlock()
if err != nil {
return err
}
}
co... | go | func (f *FileWriter) Close() error {
if f.closed {
return io.ErrClosedPipe
}
var lastBlock *hdfs.ExtendedBlockProto
if f.blockWriter != nil {
lastBlock = f.blockWriter.Block.GetB()
// Close the blockWriter, flushing any buffered packets.
err := f.finalizeBlock()
if err != nil {
return err
}
}
co... | [
"func",
"(",
"f",
"*",
"FileWriter",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"f",
".",
"closed",
"{",
"return",
"io",
".",
"ErrClosedPipe",
"\n",
"}",
"\n\n",
"var",
"lastBlock",
"*",
"hdfs",
".",
"ExtendedBlockProto",
"\n",
"if",
"f",
".",
"bloc... | // Close closes the file, writing any remaining data out to disk and waiting
// for acknowledgements from the datanodes. It is important that Close is called
// after all data has been written. | [
"Close",
"closes",
"the",
"file",
"writing",
"any",
"remaining",
"data",
"out",
"to",
"disk",
"and",
"waiting",
"for",
"acknowledgements",
"from",
"the",
"datanodes",
".",
"It",
"is",
"important",
"that",
"Close",
"is",
"called",
"after",
"all",
"data",
"has... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/file_writer.go#L209-L238 |
26,988 | colinmarc/hdfs | content_summary.go | GetContentSummary | func (c *Client) GetContentSummary(name string) (*ContentSummary, error) {
cs, err := c.getContentSummary(name)
if err != nil {
err = &os.PathError{"content summary", name, interpretException(err)}
}
return cs, err
} | go | func (c *Client) GetContentSummary(name string) (*ContentSummary, error) {
cs, err := c.getContentSummary(name)
if err != nil {
err = &os.PathError{"content summary", name, interpretException(err)}
}
return cs, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetContentSummary",
"(",
"name",
"string",
")",
"(",
"*",
"ContentSummary",
",",
"error",
")",
"{",
"cs",
",",
"err",
":=",
"c",
".",
"getContentSummary",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // GetContentSummary returns a ContentSummary representing the named file or
// directory. The summary contains information about the entire tree rooted
// in the named file; for instance, it can return the total size of all | [
"GetContentSummary",
"returns",
"a",
"ContentSummary",
"representing",
"the",
"named",
"file",
"or",
"directory",
".",
"The",
"summary",
"contains",
"information",
"about",
"the",
"entire",
"tree",
"rooted",
"in",
"the",
"named",
"file",
";",
"for",
"instance",
... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/content_summary.go#L21-L28 |
26,989 | colinmarc/hdfs | mkdir.go | Mkdir | func (c *Client) Mkdir(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, false)
} | go | func (c *Client) Mkdir(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, false)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Mkdir",
"(",
"dirname",
"string",
",",
"perm",
"os",
".",
"FileMode",
")",
"error",
"{",
"return",
"c",
".",
"mkdir",
"(",
"dirname",
",",
"perm",
",",
"false",
")",
"\n",
"}"
] | // Mkdir creates a new directory with the specified name and permission bits. | [
"Mkdir",
"creates",
"a",
"new",
"directory",
"with",
"the",
"specified",
"name",
"and",
"permission",
"bits",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/mkdir.go#L12-L14 |
26,990 | colinmarc/hdfs | mkdir.go | MkdirAll | func (c *Client) MkdirAll(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, true)
} | go | func (c *Client) MkdirAll(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, true)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"MkdirAll",
"(",
"dirname",
"string",
",",
"perm",
"os",
".",
"FileMode",
")",
"error",
"{",
"return",
"c",
".",
"mkdir",
"(",
"dirname",
",",
"perm",
",",
"true",
")",
"\n",
"}"
] | // MkdirAll creates a directory for dirname, along with any necessary parents,
// and returns nil, or else returns an error. The permission bits perm are used
// for all directories that MkdirAll creates. If dirname is already a directory,
// MkdirAll does nothing and returns nil. | [
"MkdirAll",
"creates",
"a",
"directory",
"for",
"dirname",
"along",
"with",
"any",
"necessary",
"parents",
"and",
"returns",
"nil",
"or",
"else",
"returns",
"an",
"error",
".",
"The",
"permission",
"bits",
"perm",
"are",
"used",
"for",
"all",
"directories",
... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/mkdir.go#L20-L22 |
26,991 | colinmarc/hdfs | hadoopconf/hadoopconf.go | Load | func Load(path string) (HadoopConf, error) {
var conf HadoopConf
for _, file := range confFiles {
pList := propertyList{}
f, err := ioutil.ReadFile(filepath.Join(path, file))
if os.IsNotExist(err) {
continue
} else if err != nil {
return conf, err
}
err = xml.Unmarshal(f, &pList)
if err != nil {... | go | func Load(path string) (HadoopConf, error) {
var conf HadoopConf
for _, file := range confFiles {
pList := propertyList{}
f, err := ioutil.ReadFile(filepath.Join(path, file))
if os.IsNotExist(err) {
continue
} else if err != nil {
return conf, err
}
err = xml.Unmarshal(f, &pList)
if err != nil {... | [
"func",
"Load",
"(",
"path",
"string",
")",
"(",
"HadoopConf",
",",
"error",
")",
"{",
"var",
"conf",
"HadoopConf",
"\n\n",
"for",
"_",
",",
"file",
":=",
"range",
"confFiles",
"{",
"pList",
":=",
"propertyList",
"{",
"}",
"\n",
"f",
",",
"err",
":="... | // Load returns a HadoopConf object representing configuration from the
// specified path. It will parse core-site.xml, hdfs-site.xml, and
// mapred-site.xml.
//
// If no configuration files could be found, Load returns a nil map. If the
// configuration files exist but there was an error opening or parsing them,
// th... | [
"Load",
"returns",
"a",
"HadoopConf",
"object",
"representing",
"configuration",
"from",
"the",
"specified",
"path",
".",
"It",
"will",
"parse",
"core",
"-",
"site",
".",
"xml",
"hdfs",
"-",
"site",
".",
"xml",
"and",
"mapred",
"-",
"site",
".",
"xml",
"... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/hadoopconf/hadoopconf.go#L64-L91 |
26,992 | colinmarc/hdfs | perms.go | Chmod | func (c *Client) Chmod(name string, perm os.FileMode) error {
req := &hdfs.SetPermissionRequestProto{
Src: proto.String(name),
Permission: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
}
resp := &hdfs.SetPermissionResponseProto{}
err := c.namenode.Execute("setPermission", req, resp)
if err... | go | func (c *Client) Chmod(name string, perm os.FileMode) error {
req := &hdfs.SetPermissionRequestProto{
Src: proto.String(name),
Permission: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
}
resp := &hdfs.SetPermissionResponseProto{}
err := c.namenode.Execute("setPermission", req, resp)
if err... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Chmod",
"(",
"name",
"string",
",",
"perm",
"os",
".",
"FileMode",
")",
"error",
"{",
"req",
":=",
"&",
"hdfs",
".",
"SetPermissionRequestProto",
"{",
"Src",
":",
"proto",
".",
"String",
"(",
"name",
")",
",",
... | // Chmod changes the mode of the named file to mode. | [
"Chmod",
"changes",
"the",
"mode",
"of",
"the",
"named",
"file",
"to",
"mode",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/perms.go#L12-L25 |
26,993 | colinmarc/hdfs | internal/rpc/block_reader.go | SetDeadline | func (br *BlockReader) SetDeadline(t time.Time) error {
br.deadline = t
if br.conn != nil {
return br.conn.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | go | func (br *BlockReader) SetDeadline(t time.Time) error {
br.deadline = t
if br.conn != nil {
return br.conn.SetDeadline(t)
}
// Return the error at connection time.
return nil
} | [
"func",
"(",
"br",
"*",
"BlockReader",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"br",
".",
"deadline",
"=",
"t",
"\n",
"if",
"br",
".",
"conn",
"!=",
"nil",
"{",
"return",
"br",
".",
"conn",
".",
"SetDeadline",
"(",
"... | // SetDeadline sets the deadline for future Read calls. A zero value for t
// means Read will not time out. | [
"SetDeadline",
"sets",
"the",
"deadline",
"for",
"future",
"Read",
"calls",
".",
"A",
"zero",
"value",
"for",
"t",
"means",
"Read",
"will",
"not",
"time",
"out",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_reader.go#L44-L52 |
26,994 | colinmarc/hdfs | internal/rpc/block_reader.go | connectNext | func (br *BlockReader) connectNext() error {
address := br.datanodes.next()
if br.DialFunc == nil {
br.DialFunc = (&net.Dialer{}).DialContext
}
conn, err := br.DialFunc(context.Background(), "tcp", address)
if err != nil {
return err
}
err = br.writeBlockReadRequest(conn)
if err != nil {
return err
}
... | go | func (br *BlockReader) connectNext() error {
address := br.datanodes.next()
if br.DialFunc == nil {
br.DialFunc = (&net.Dialer{}).DialContext
}
conn, err := br.DialFunc(context.Background(), "tcp", address)
if err != nil {
return err
}
err = br.writeBlockReadRequest(conn)
if err != nil {
return err
}
... | [
"func",
"(",
"br",
"*",
"BlockReader",
")",
"connectNext",
"(",
")",
"error",
"{",
"address",
":=",
"br",
".",
"datanodes",
".",
"next",
"(",
")",
"\n\n",
"if",
"br",
".",
"DialFunc",
"==",
"nil",
"{",
"br",
".",
"DialFunc",
"=",
"(",
"&",
"net",
... | // connectNext pops a datanode from the list based on previous failures, and
// connects to it. | [
"connectNext",
"pops",
"a",
"datanode",
"from",
"the",
"list",
"based",
"on",
"previous",
"failures",
"and",
"connects",
"to",
"it",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_reader.go#L130-L194 |
26,995 | colinmarc/hdfs | internal/rpc/kerberos.go | getKerberosTicket | func (c *NamenodeConnection) getKerberosTicket() (gssapi.NegTokenInit, krbtypes.EncryptionKey, error) {
host, _, _ := net.SplitHostPort(c.host.address)
spn := replaceSPNHostWildcard(c.kerberosServicePrincipleName, host)
ticket, key, err := c.kerberosClient.GetServiceTicket(spn)
if err != nil {
return gssapi.NegT... | go | func (c *NamenodeConnection) getKerberosTicket() (gssapi.NegTokenInit, krbtypes.EncryptionKey, error) {
host, _, _ := net.SplitHostPort(c.host.address)
spn := replaceSPNHostWildcard(c.kerberosServicePrincipleName, host)
ticket, key, err := c.kerberosClient.GetServiceTicket(spn)
if err != nil {
return gssapi.NegT... | [
"func",
"(",
"c",
"*",
"NamenodeConnection",
")",
"getKerberosTicket",
"(",
")",
"(",
"gssapi",
".",
"NegTokenInit",
",",
"krbtypes",
".",
"EncryptionKey",
",",
"error",
")",
"{",
"host",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"c",
... | // getKerberosTicket returns an initial kerberos negotiation token and the
// paired session key, along with an error if any occured. | [
"getKerberosTicket",
"returns",
"an",
"initial",
"kerberos",
"negotiation",
"token",
"and",
"the",
"paired",
"session",
"key",
"along",
"with",
"an",
"error",
"if",
"any",
"occured",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/kerberos.go#L128-L139 |
26,996 | colinmarc/hdfs | internal/rpc/block_write_stream.go | finish | func (s *blockWriteStream) finish() error {
if s.closed {
return nil
}
s.closed = true
if err := s.getAckError(); err != nil {
return err
}
err := s.flush(true)
if err != nil {
return err
}
// The last packet has no data; it's just a marker that the block is finished.
lastPacket := outboundPacket{
... | go | func (s *blockWriteStream) finish() error {
if s.closed {
return nil
}
s.closed = true
if err := s.getAckError(); err != nil {
return err
}
err := s.flush(true)
if err != nil {
return err
}
// The last packet has no data; it's just a marker that the block is finished.
lastPacket := outboundPacket{
... | [
"func",
"(",
"s",
"*",
"blockWriteStream",
")",
"finish",
"(",
")",
"error",
"{",
"if",
"s",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"closed",
"=",
"true",
"\n\n",
"if",
"err",
":=",
"s",
".",
"getAckError",
"(",
")",
";",... | // finish flushes the rest of the buffered bytes, and then sends a final empty
// packet signifying the end of the block. | [
"finish",
"flushes",
"the",
"rest",
"of",
"the",
"buffered",
"bytes",
"and",
"then",
"sends",
"a",
"final",
"empty",
"packet",
"signifying",
"the",
"end",
"of",
"the",
"block",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_write_stream.go#L108-L147 |
26,997 | colinmarc/hdfs | internal/rpc/block_write_stream.go | flush | func (s *blockWriteStream) flush(force bool) error {
if err := s.getAckError(); err != nil {
return err
}
for s.buf.Len() > 0 && (force || s.buf.Len() >= outboundPacketSize) {
packet := s.makePacket()
s.packets <- packet
s.offset += int64(len(packet.data))
s.seqno++
err := s.writePacket(packet)
if er... | go | func (s *blockWriteStream) flush(force bool) error {
if err := s.getAckError(); err != nil {
return err
}
for s.buf.Len() > 0 && (force || s.buf.Len() >= outboundPacketSize) {
packet := s.makePacket()
s.packets <- packet
s.offset += int64(len(packet.data))
s.seqno++
err := s.writePacket(packet)
if er... | [
"func",
"(",
"s",
"*",
"blockWriteStream",
")",
"flush",
"(",
"force",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"getAckError",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"s",
".",
"buf",
".",... | // flush parcels out the buffered bytes into packets, which it then flushes to
// the datanode. We keep around a reference to the packet, in case the ack
// fails, and we need to send it again later. | [
"flush",
"parcels",
"out",
"the",
"buffered",
"bytes",
"into",
"packets",
"which",
"it",
"then",
"flushes",
"to",
"the",
"datanode",
".",
"We",
"keep",
"around",
"a",
"reference",
"to",
"the",
"packet",
"in",
"case",
"the",
"ack",
"fails",
"and",
"we",
"... | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_write_stream.go#L152-L170 |
26,998 | colinmarc/hdfs | internal/rpc/block_write_stream.go | ackPackets | func (s *blockWriteStream) ackPackets() {
reader := bufio.NewReader(s.conn)
for {
p, ok := <-s.packets
if !ok {
// All packets all acked.
return
}
// If we fail to read the ack at all, that counts as a failure from the
// first datanode (the one we're connected to).
ack := &hdfs.PipelineAckProto{}... | go | func (s *blockWriteStream) ackPackets() {
reader := bufio.NewReader(s.conn)
for {
p, ok := <-s.packets
if !ok {
// All packets all acked.
return
}
// If we fail to read the ack at all, that counts as a failure from the
// first datanode (the one we're connected to).
ack := &hdfs.PipelineAckProto{}... | [
"func",
"(",
"s",
"*",
"blockWriteStream",
")",
"ackPackets",
"(",
")",
"{",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"s",
".",
"conn",
")",
"\n\n",
"for",
"{",
"p",
",",
"ok",
":=",
"<-",
"s",
".",
"packets",
"\n",
"if",
"!",
"ok",
"{",
... | // ackPackets is meant to run in the background, reading acks and setting
// ackError if one fails. | [
"ackPackets",
"is",
"meant",
"to",
"run",
"in",
"the",
"background",
"reading",
"acks",
"and",
"setting",
"ackError",
"if",
"one",
"fails",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/internal/rpc/block_write_stream.go#L217-L255 |
26,999 | colinmarc/hdfs | stat.go | Stat | func (c *Client) Stat(name string) (os.FileInfo, error) {
fi, err := c.getFileInfo(name)
if err != nil {
err = &os.PathError{"stat", name, interpretException(err)}
}
return fi, err
} | go | func (c *Client) Stat(name string) (os.FileInfo, error) {
fi, err := c.getFileInfo(name)
if err != nil {
err = &os.PathError{"stat", name, interpretException(err)}
}
return fi, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Stat",
"(",
"name",
"string",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"fi",
",",
"err",
":=",
"c",
".",
"getFileInfo",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
... | // Stat returns an os.FileInfo describing the named file or directory. | [
"Stat",
"returns",
"an",
"os",
".",
"FileInfo",
"describing",
"the",
"named",
"file",
"or",
"directory",
"."
] | 6f7e441ec688730014b4ca08657db358d7a45b87 | https://github.com/colinmarc/hdfs/blob/6f7e441ec688730014b4ca08657db358d7a45b87/stat.go#L20-L27 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.