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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
20,200
|
cbednarski/hostess
|
commands.go
|
Fixed
|
func Fixed(c *cli.Context) {
hostsfile := AlwaysLoadHostFile(c)
if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) {
MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts", GetHostsPath()))
os.Exit(0)
} else {
MaybePrintln(c, fmt.Sprintf("%s is not formatted. Use hostess fix to format it", GetHostsPath()))
os.Exit(1)
}
}
|
go
|
func Fixed(c *cli.Context) {
hostsfile := AlwaysLoadHostFile(c)
if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) {
MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts", GetHostsPath()))
os.Exit(0)
} else {
MaybePrintln(c, fmt.Sprintf("%s is not formatted. Use hostess fix to format it", GetHostsPath()))
os.Exit(1)
}
}
|
[
"func",
"Fixed",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"hostsfile",
":=",
"AlwaysLoadHostFile",
"(",
"c",
")",
"\n",
"if",
"bytes",
".",
"Equal",
"(",
"hostsfile",
".",
"GetData",
"(",
")",
",",
"hostsfile",
".",
"Format",
"(",
")",
")",
"{",
"MaybePrintln",
"(",
"c",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"GetHostsPath",
"(",
")",
")",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"else",
"{",
"MaybePrintln",
"(",
"c",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"GetHostsPath",
"(",
")",
")",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"}"
] |
// Fixed command removes duplicates and conflicts from the hosts file
|
[
"Fixed",
"command",
"removes",
"duplicates",
"and",
"conflicts",
"from",
"the",
"hosts",
"file"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L248-L257
|
20,201
|
cbednarski/hostess
|
commands.go
|
Dump
|
func Dump(c *cli.Context) {
hostsfile := AlwaysLoadHostFile(c)
jsonbytes, err := hostsfile.Hosts.Dump()
if err != nil {
MaybeError(c, err.Error())
}
fmt.Println(fmt.Sprintf("%s", jsonbytes))
}
|
go
|
func Dump(c *cli.Context) {
hostsfile := AlwaysLoadHostFile(c)
jsonbytes, err := hostsfile.Hosts.Dump()
if err != nil {
MaybeError(c, err.Error())
}
fmt.Println(fmt.Sprintf("%s", jsonbytes))
}
|
[
"func",
"Dump",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"hostsfile",
":=",
"AlwaysLoadHostFile",
"(",
"c",
")",
"\n",
"jsonbytes",
",",
"err",
":=",
"hostsfile",
".",
"Hosts",
".",
"Dump",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"MaybeError",
"(",
"c",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"jsonbytes",
")",
")",
"\n",
"}"
] |
// Dump command outputs hosts file contents as JSON
|
[
"Dump",
"command",
"outputs",
"hosts",
"file",
"contents",
"as",
"JSON"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L260-L267
|
20,202
|
cbednarski/hostess
|
commands.go
|
Apply
|
func Apply(c *cli.Context) {
if len(c.Args()) != 1 {
MaybeError(c, "Usage should be apply [filename]")
}
filename := c.Args()[0]
jsonbytes, err := ioutil.ReadFile(filename)
if err != nil {
MaybeError(c, fmt.Sprintf("Unable to read %s: %s", filename, err))
}
hostfile := AlwaysLoadHostFile(c)
err = hostfile.Hosts.Apply(jsonbytes)
if err != nil {
MaybeError(c, fmt.Sprintf("Error applying changes to hosts file: %s", err))
}
MaybeSaveHostFile(c, hostfile)
MaybePrintln(c, fmt.Sprintf("%s applied", filename))
}
|
go
|
func Apply(c *cli.Context) {
if len(c.Args()) != 1 {
MaybeError(c, "Usage should be apply [filename]")
}
filename := c.Args()[0]
jsonbytes, err := ioutil.ReadFile(filename)
if err != nil {
MaybeError(c, fmt.Sprintf("Unable to read %s: %s", filename, err))
}
hostfile := AlwaysLoadHostFile(c)
err = hostfile.Hosts.Apply(jsonbytes)
if err != nil {
MaybeError(c, fmt.Sprintf("Error applying changes to hosts file: %s", err))
}
MaybeSaveHostFile(c, hostfile)
MaybePrintln(c, fmt.Sprintf("%s applied", filename))
}
|
[
"func",
"Apply",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"if",
"len",
"(",
"c",
".",
"Args",
"(",
")",
")",
"!=",
"1",
"{",
"MaybeError",
"(",
"c",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"filename",
":=",
"c",
".",
"Args",
"(",
")",
"[",
"0",
"]",
"\n\n",
"jsonbytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"MaybeError",
"(",
"c",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"filename",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"hostfile",
":=",
"AlwaysLoadHostFile",
"(",
"c",
")",
"\n",
"err",
"=",
"hostfile",
".",
"Hosts",
".",
"Apply",
"(",
"jsonbytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"MaybeError",
"(",
"c",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"MaybeSaveHostFile",
"(",
"c",
",",
"hostfile",
")",
"\n",
"MaybePrintln",
"(",
"c",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"filename",
")",
")",
"\n",
"}"
] |
// Apply command adds hostnames to the hosts file from JSON
|
[
"Apply",
"command",
"adds",
"hostnames",
"to",
"the",
"hosts",
"file",
"from",
"JSON"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L270-L289
|
20,203
|
cbednarski/hostess
|
hostfile.go
|
MustParseLine
|
func MustParseLine(line string) Hostlist {
hostlist, err := ParseLine(line)
if err != nil {
panic(err)
}
return hostlist
}
|
go
|
func MustParseLine(line string) Hostlist {
hostlist, err := ParseLine(line)
if err != nil {
panic(err)
}
return hostlist
}
|
[
"func",
"MustParseLine",
"(",
"line",
"string",
")",
"Hostlist",
"{",
"hostlist",
",",
"err",
":=",
"ParseLine",
"(",
"line",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"hostlist",
"\n",
"}"
] |
// MustParseLine is like ParseLine but panics instead of errors.
|
[
"MustParseLine",
"is",
"like",
"ParseLine",
"but",
"panics",
"instead",
"of",
"errors",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostfile.go#L123-L129
|
20,204
|
cbednarski/hostess
|
hostfile.go
|
Read
|
func (h *Hostfile) Read() error {
data, err := ioutil.ReadFile(h.Path)
if err == nil {
h.data = data
}
return err
}
|
go
|
func (h *Hostfile) Read() error {
data, err := ioutil.ReadFile(h.Path)
if err == nil {
h.data = data
}
return err
}
|
[
"func",
"(",
"h",
"*",
"Hostfile",
")",
"Read",
"(",
")",
"error",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"h",
".",
"Path",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"h",
".",
"data",
"=",
"data",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Read the contents of the hostfile from disk
|
[
"Read",
"the",
"contents",
"of",
"the",
"hostfile",
"from",
"disk"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostfile.go#L152-L158
|
20,205
|
cbednarski/hostess
|
hostlist.go
|
Less
|
func (h Hostlist) Less(A, B int) bool {
// Sort IPv4 before IPv6
// A is IPv4 and B is IPv6. A wins!
if !h[A].IPv6 && h[B].IPv6 {
return true
}
// A is IPv6 but B is IPv4. A loses!
if h[A].IPv6 && !h[B].IPv6 {
return false
}
// Sort "localhost" at the top
if h[A].Domain == "localhost" {
return true
}
if h[B].Domain == "localhost" {
return false
}
// Compare the the IP addresses (byte array)
// We want to push 127. to the top so we're going to mark it zero.
surrogateA := MakeSurrogateIP(h[A].IP)
surrogateB := MakeSurrogateIP(h[B].IP)
if !surrogateA.Equal(surrogateB) {
for charIndex := range surrogateA {
// A and B's IPs differ at this index, and A is less. A wins!
if surrogateA[charIndex] < surrogateB[charIndex] {
return true
}
// A and B's IPs differ at this index, and B is less. A loses!
if surrogateA[charIndex] > surrogateB[charIndex] {
return false
}
}
// If we got here then the IPs are the same and we want to continue on
// to the domain sorting section.
}
// Prep for sorting by domain name
aLength := len(h[A].Domain)
bLength := len(h[B].Domain)
max := aLength
if bLength > max {
max = bLength
}
// Sort domains alphabetically
// TODO: This works best if domains are lowercased. However, we do not
// enforce lowercase because of UTF-8 domain names, which may be broken by
// case folding. There is a way to do this correctly but it's complicated
// so I'm not going to do it right now.
for charIndex := 0; charIndex < max; charIndex++ {
// This index is longer than A, so A is shorter. A wins!
if charIndex >= aLength {
return true
}
// This index is longer than B, so B is shorter. A loses!
if charIndex >= bLength {
return false
}
// A and B differ at this index and A is less. A wins!
if h[A].Domain[charIndex] < h[B].Domain[charIndex] {
return true
}
// A and B differ at this index and B is less. A loses!
if h[A].Domain[charIndex] > h[B].Domain[charIndex] {
return false
}
}
// If we got here then A and B are the same -- by definition A is not Less
// than B so we return false. Technically we shouldn't get here since Add
// should not allow duplicates, but we'll guard anyway.
return false
}
|
go
|
func (h Hostlist) Less(A, B int) bool {
// Sort IPv4 before IPv6
// A is IPv4 and B is IPv6. A wins!
if !h[A].IPv6 && h[B].IPv6 {
return true
}
// A is IPv6 but B is IPv4. A loses!
if h[A].IPv6 && !h[B].IPv6 {
return false
}
// Sort "localhost" at the top
if h[A].Domain == "localhost" {
return true
}
if h[B].Domain == "localhost" {
return false
}
// Compare the the IP addresses (byte array)
// We want to push 127. to the top so we're going to mark it zero.
surrogateA := MakeSurrogateIP(h[A].IP)
surrogateB := MakeSurrogateIP(h[B].IP)
if !surrogateA.Equal(surrogateB) {
for charIndex := range surrogateA {
// A and B's IPs differ at this index, and A is less. A wins!
if surrogateA[charIndex] < surrogateB[charIndex] {
return true
}
// A and B's IPs differ at this index, and B is less. A loses!
if surrogateA[charIndex] > surrogateB[charIndex] {
return false
}
}
// If we got here then the IPs are the same and we want to continue on
// to the domain sorting section.
}
// Prep for sorting by domain name
aLength := len(h[A].Domain)
bLength := len(h[B].Domain)
max := aLength
if bLength > max {
max = bLength
}
// Sort domains alphabetically
// TODO: This works best if domains are lowercased. However, we do not
// enforce lowercase because of UTF-8 domain names, which may be broken by
// case folding. There is a way to do this correctly but it's complicated
// so I'm not going to do it right now.
for charIndex := 0; charIndex < max; charIndex++ {
// This index is longer than A, so A is shorter. A wins!
if charIndex >= aLength {
return true
}
// This index is longer than B, so B is shorter. A loses!
if charIndex >= bLength {
return false
}
// A and B differ at this index and A is less. A wins!
if h[A].Domain[charIndex] < h[B].Domain[charIndex] {
return true
}
// A and B differ at this index and B is less. A loses!
if h[A].Domain[charIndex] > h[B].Domain[charIndex] {
return false
}
}
// If we got here then A and B are the same -- by definition A is not Less
// than B so we return false. Technically we shouldn't get here since Add
// should not allow duplicates, but we'll guard anyway.
return false
}
|
[
"func",
"(",
"h",
"Hostlist",
")",
"Less",
"(",
"A",
",",
"B",
"int",
")",
"bool",
"{",
"// Sort IPv4 before IPv6",
"// A is IPv4 and B is IPv6. A wins!",
"if",
"!",
"h",
"[",
"A",
"]",
".",
"IPv6",
"&&",
"h",
"[",
"B",
"]",
".",
"IPv6",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// A is IPv6 but B is IPv4. A loses!",
"if",
"h",
"[",
"A",
"]",
".",
"IPv6",
"&&",
"!",
"h",
"[",
"B",
"]",
".",
"IPv6",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Sort \"localhost\" at the top",
"if",
"h",
"[",
"A",
"]",
".",
"Domain",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"h",
"[",
"B",
"]",
".",
"Domain",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Compare the the IP addresses (byte array)",
"// We want to push 127. to the top so we're going to mark it zero.",
"surrogateA",
":=",
"MakeSurrogateIP",
"(",
"h",
"[",
"A",
"]",
".",
"IP",
")",
"\n",
"surrogateB",
":=",
"MakeSurrogateIP",
"(",
"h",
"[",
"B",
"]",
".",
"IP",
")",
"\n",
"if",
"!",
"surrogateA",
".",
"Equal",
"(",
"surrogateB",
")",
"{",
"for",
"charIndex",
":=",
"range",
"surrogateA",
"{",
"// A and B's IPs differ at this index, and A is less. A wins!",
"if",
"surrogateA",
"[",
"charIndex",
"]",
"<",
"surrogateB",
"[",
"charIndex",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// A and B's IPs differ at this index, and B is less. A loses!",
"if",
"surrogateA",
"[",
"charIndex",
"]",
">",
"surrogateB",
"[",
"charIndex",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"// If we got here then the IPs are the same and we want to continue on",
"// to the domain sorting section.",
"}",
"\n\n",
"// Prep for sorting by domain name",
"aLength",
":=",
"len",
"(",
"h",
"[",
"A",
"]",
".",
"Domain",
")",
"\n",
"bLength",
":=",
"len",
"(",
"h",
"[",
"B",
"]",
".",
"Domain",
")",
"\n",
"max",
":=",
"aLength",
"\n",
"if",
"bLength",
">",
"max",
"{",
"max",
"=",
"bLength",
"\n",
"}",
"\n\n",
"// Sort domains alphabetically",
"// TODO: This works best if domains are lowercased. However, we do not",
"// enforce lowercase because of UTF-8 domain names, which may be broken by",
"// case folding. There is a way to do this correctly but it's complicated",
"// so I'm not going to do it right now.",
"for",
"charIndex",
":=",
"0",
";",
"charIndex",
"<",
"max",
";",
"charIndex",
"++",
"{",
"// This index is longer than A, so A is shorter. A wins!",
"if",
"charIndex",
">=",
"aLength",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// This index is longer than B, so B is shorter. A loses!",
"if",
"charIndex",
">=",
"bLength",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// A and B differ at this index and A is less. A wins!",
"if",
"h",
"[",
"A",
"]",
".",
"Domain",
"[",
"charIndex",
"]",
"<",
"h",
"[",
"B",
"]",
".",
"Domain",
"[",
"charIndex",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// A and B differ at this index and B is less. A loses!",
"if",
"h",
"[",
"A",
"]",
".",
"Domain",
"[",
"charIndex",
"]",
">",
"h",
"[",
"B",
"]",
".",
"Domain",
"[",
"charIndex",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If we got here then A and B are the same -- by definition A is not Less",
"// than B so we return false. Technically we shouldn't get here since Add",
"// should not allow duplicates, but we'll guard anyway.",
"return",
"false",
"\n",
"}"
] |
// Less determines the sort order of two Hostnames, part of sort.Interface
|
[
"Less",
"determines",
"the",
"sort",
"order",
"of",
"two",
"Hostnames",
"part",
"of",
"sort",
".",
"Interface"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L52-L126
|
20,206
|
cbednarski/hostess
|
hostlist.go
|
Swap
|
func (h Hostlist) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
|
go
|
func (h Hostlist) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
|
[
"func",
"(",
"h",
"Hostlist",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"h",
"[",
"i",
"]",
",",
"h",
"[",
"j",
"]",
"=",
"h",
"[",
"j",
"]",
",",
"h",
"[",
"i",
"]",
"\n",
"}"
] |
// Swap changes the position of two Hostnames, part of sort.Interface
|
[
"Swap",
"changes",
"the",
"position",
"of",
"two",
"Hostnames",
"part",
"of",
"sort",
".",
"Interface"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L129-L131
|
20,207
|
cbednarski/hostess
|
hostlist.go
|
Contains
|
func (h *Hostlist) Contains(b *Hostname) bool {
for _, a := range *h {
if a.Equal(b) {
return true
}
}
return false
}
|
go
|
func (h *Hostlist) Contains(b *Hostname) bool {
for _, a := range *h {
if a.Equal(b) {
return true
}
}
return false
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"Contains",
"(",
"b",
"*",
"Hostname",
")",
"bool",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"*",
"h",
"{",
"if",
"a",
".",
"Equal",
"(",
"b",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// Contains returns true if this Hostlist has the specified Hostname
|
[
"Contains",
"returns",
"true",
"if",
"this",
"Hostlist",
"has",
"the",
"specified",
"Hostname"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L144-L151
|
20,208
|
cbednarski/hostess
|
hostlist.go
|
ContainsDomain
|
func (h *Hostlist) ContainsDomain(domain string) bool {
for _, hostname := range *h {
if hostname.Domain == domain {
return true
}
}
return false
}
|
go
|
func (h *Hostlist) ContainsDomain(domain string) bool {
for _, hostname := range *h {
if hostname.Domain == domain {
return true
}
}
return false
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"ContainsDomain",
"(",
"domain",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// ContainsDomain returns true if a Hostname in this Hostlist matches domain
|
[
"ContainsDomain",
"returns",
"true",
"if",
"a",
"Hostname",
"in",
"this",
"Hostlist",
"matches",
"domain"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L154-L161
|
20,209
|
cbednarski/hostess
|
hostlist.go
|
ContainsIP
|
func (h *Hostlist) ContainsIP(IP net.IP) bool {
for _, hostname := range *h {
if hostname.EqualIP(IP) {
return true
}
}
return false
}
|
go
|
func (h *Hostlist) ContainsIP(IP net.IP) bool {
for _, hostname := range *h {
if hostname.EqualIP(IP) {
return true
}
}
return false
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"ContainsIP",
"(",
"IP",
"net",
".",
"IP",
")",
"bool",
"{",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"EqualIP",
"(",
"IP",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// ContainsIP returns true if a Hostname in this Hostlist matches IP
|
[
"ContainsIP",
"returns",
"true",
"if",
"a",
"Hostname",
"in",
"this",
"Hostlist",
"matches",
"IP"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L164-L171
|
20,210
|
cbednarski/hostess
|
hostlist.go
|
IndexOf
|
func (h *Hostlist) IndexOf(host *Hostname) int {
for index, found := range *h {
if found.Equal(host) {
return index
}
}
return -1
}
|
go
|
func (h *Hostlist) IndexOf(host *Hostname) int {
for index, found := range *h {
if found.Equal(host) {
return index
}
}
return -1
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"IndexOf",
"(",
"host",
"*",
"Hostname",
")",
"int",
"{",
"for",
"index",
",",
"found",
":=",
"range",
"*",
"h",
"{",
"if",
"found",
".",
"Equal",
"(",
"host",
")",
"{",
"return",
"index",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] |
// IndexOf will indicate the index of a Hostname in Hostlist, or -1 if it is
// not found.
|
[
"IndexOf",
"will",
"indicate",
"the",
"index",
"of",
"a",
"Hostname",
"in",
"Hostlist",
"or",
"-",
"1",
"if",
"it",
"is",
"not",
"found",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L208-L215
|
20,211
|
cbednarski/hostess
|
hostlist.go
|
IndexOfDomainV
|
func (h *Hostlist) IndexOfDomainV(domain string, version int) int {
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for index, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
return index
}
}
return -1
}
|
go
|
func (h *Hostlist) IndexOfDomainV(domain string, version int) int {
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for index, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
return index
}
}
return -1
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"IndexOfDomainV",
"(",
"domain",
"string",
",",
"version",
"int",
")",
"int",
"{",
"if",
"version",
"!=",
"4",
"&&",
"version",
"!=",
"6",
"{",
"panic",
"(",
"ErrInvalidVersionArg",
")",
"\n",
"}",
"\n",
"for",
"index",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"&&",
"hostname",
".",
"IPv6",
"==",
"(",
"version",
"==",
"6",
")",
"{",
"return",
"index",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] |
// IndexOfDomainV will indicate the index of a Hostname in Hostlist that has
// the same domain and IP version, or -1 if it is not found.
//
// This function will panic if IP version is not 4 or 6.
|
[
"IndexOfDomainV",
"will",
"indicate",
"the",
"index",
"of",
"a",
"Hostname",
"in",
"Hostlist",
"that",
"has",
"the",
"same",
"domain",
"and",
"IP",
"version",
"or",
"-",
"1",
"if",
"it",
"is",
"not",
"found",
".",
"This",
"function",
"will",
"panic",
"if",
"IP",
"version",
"is",
"not",
"4",
"or",
"6",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L221-L231
|
20,212
|
cbednarski/hostess
|
hostlist.go
|
RemoveDomain
|
func (h *Hostlist) RemoveDomain(domain string) int {
return h.RemoveDomainV(domain, 4) + h.RemoveDomainV(domain, 6)
}
|
go
|
func (h *Hostlist) RemoveDomain(domain string) int {
return h.RemoveDomainV(domain, 4) + h.RemoveDomainV(domain, 6)
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"RemoveDomain",
"(",
"domain",
"string",
")",
"int",
"{",
"return",
"h",
".",
"RemoveDomainV",
"(",
"domain",
",",
"4",
")",
"+",
"h",
".",
"RemoveDomainV",
"(",
"domain",
",",
"6",
")",
"\n",
"}"
] |
// RemoveDomain removes both IPv4 and IPv6 Hostname entries matching domain.
// Returns the number of entries removed.
|
[
"RemoveDomain",
"removes",
"both",
"IPv4",
"and",
"IPv6",
"Hostname",
"entries",
"matching",
"domain",
".",
"Returns",
"the",
"number",
"of",
"entries",
"removed",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L246-L248
|
20,213
|
cbednarski/hostess
|
hostlist.go
|
RemoveDomainV
|
func (h *Hostlist) RemoveDomainV(domain string, version int) int {
return h.Remove(h.IndexOfDomainV(domain, version))
}
|
go
|
func (h *Hostlist) RemoveDomainV(domain string, version int) int {
return h.Remove(h.IndexOfDomainV(domain, version))
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"RemoveDomainV",
"(",
"domain",
"string",
",",
"version",
"int",
")",
"int",
"{",
"return",
"h",
".",
"Remove",
"(",
"h",
".",
"IndexOfDomainV",
"(",
"domain",
",",
"version",
")",
")",
"\n",
"}"
] |
// RemoveDomainV removes a Hostname entry matching the domain and IP version.
|
[
"RemoveDomainV",
"removes",
"a",
"Hostname",
"entry",
"matching",
"the",
"domain",
"and",
"IP",
"version",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L251-L253
|
20,214
|
cbednarski/hostess
|
hostlist.go
|
Enable
|
func (h *Hostlist) Enable(domain string) bool {
found := false
for _, hostname := range *h {
if hostname.Domain == domain {
hostname.Enabled = true
found = true
}
}
return found
}
|
go
|
func (h *Hostlist) Enable(domain string) bool {
found := false
for _, hostname := range *h {
if hostname.Domain == domain {
hostname.Enabled = true
found = true
}
}
return found
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"Enable",
"(",
"domain",
"string",
")",
"bool",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"{",
"hostname",
".",
"Enabled",
"=",
"true",
"\n",
"found",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"found",
"\n",
"}"
] |
// Enable will change any Hostnames matching domain to be enabled.
|
[
"Enable",
"will",
"change",
"any",
"Hostnames",
"matching",
"domain",
"to",
"be",
"enabled",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L256-L265
|
20,215
|
cbednarski/hostess
|
hostlist.go
|
EnableV
|
func (h *Hostlist) EnableV(domain string, version int) bool {
found := false
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for _, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
hostname.Enabled = true
found = true
}
}
return found
}
|
go
|
func (h *Hostlist) EnableV(domain string, version int) bool {
found := false
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for _, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
hostname.Enabled = true
found = true
}
}
return found
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"EnableV",
"(",
"domain",
"string",
",",
"version",
"int",
")",
"bool",
"{",
"found",
":=",
"false",
"\n",
"if",
"version",
"!=",
"4",
"&&",
"version",
"!=",
"6",
"{",
"panic",
"(",
"ErrInvalidVersionArg",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"&&",
"hostname",
".",
"IPv6",
"==",
"(",
"version",
"==",
"6",
")",
"{",
"hostname",
".",
"Enabled",
"=",
"true",
"\n",
"found",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"found",
"\n",
"}"
] |
// EnableV will change a Hostname matching domain and IP version to be enabled.
//
// This function will panic if IP version is not 4 or 6.
|
[
"EnableV",
"will",
"change",
"a",
"Hostname",
"matching",
"domain",
"and",
"IP",
"version",
"to",
"be",
"enabled",
".",
"This",
"function",
"will",
"panic",
"if",
"IP",
"version",
"is",
"not",
"4",
"or",
"6",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L270-L282
|
20,216
|
cbednarski/hostess
|
hostlist.go
|
FilterByIP
|
func (h *Hostlist) FilterByIP(IP net.IP) (hostnames []*Hostname) {
for _, hostname := range *h {
if hostname.IP.Equal(IP) {
hostnames = append(hostnames, hostname)
}
}
return
}
|
go
|
func (h *Hostlist) FilterByIP(IP net.IP) (hostnames []*Hostname) {
for _, hostname := range *h {
if hostname.IP.Equal(IP) {
hostnames = append(hostnames, hostname)
}
}
return
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"FilterByIP",
"(",
"IP",
"net",
".",
"IP",
")",
"(",
"hostnames",
"[",
"]",
"*",
"Hostname",
")",
"{",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"IP",
".",
"Equal",
"(",
"IP",
")",
"{",
"hostnames",
"=",
"append",
"(",
"hostnames",
",",
"hostname",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// FilterByIP filters the list of hostnames by IP address.
|
[
"FilterByIP",
"filters",
"the",
"list",
"of",
"hostnames",
"by",
"IP",
"address",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L314-L321
|
20,217
|
cbednarski/hostess
|
hostlist.go
|
FilterByDomain
|
func (h *Hostlist) FilterByDomain(domain string) (hostnames []*Hostname) {
for _, hostname := range *h {
if hostname.Domain == domain {
hostnames = append(hostnames, hostname)
}
}
return
}
|
go
|
func (h *Hostlist) FilterByDomain(domain string) (hostnames []*Hostname) {
for _, hostname := range *h {
if hostname.Domain == domain {
hostnames = append(hostnames, hostname)
}
}
return
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"FilterByDomain",
"(",
"domain",
"string",
")",
"(",
"hostnames",
"[",
"]",
"*",
"Hostname",
")",
"{",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"{",
"hostnames",
"=",
"append",
"(",
"hostnames",
",",
"hostname",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// FilterByDomain filters the list of hostnames by Domain.
|
[
"FilterByDomain",
"filters",
"the",
"list",
"of",
"hostnames",
"by",
"Domain",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L324-L331
|
20,218
|
cbednarski/hostess
|
hostlist.go
|
FilterByDomainV
|
func (h *Hostlist) FilterByDomainV(domain string, version int) (hostnames []*Hostname) {
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for _, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
hostnames = append(hostnames, hostname)
}
}
return
}
|
go
|
func (h *Hostlist) FilterByDomainV(domain string, version int) (hostnames []*Hostname) {
if version != 4 && version != 6 {
panic(ErrInvalidVersionArg)
}
for _, hostname := range *h {
if hostname.Domain == domain && hostname.IPv6 == (version == 6) {
hostnames = append(hostnames, hostname)
}
}
return
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"FilterByDomainV",
"(",
"domain",
"string",
",",
"version",
"int",
")",
"(",
"hostnames",
"[",
"]",
"*",
"Hostname",
")",
"{",
"if",
"version",
"!=",
"4",
"&&",
"version",
"!=",
"6",
"{",
"panic",
"(",
"ErrInvalidVersionArg",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"hostname",
":=",
"range",
"*",
"h",
"{",
"if",
"hostname",
".",
"Domain",
"==",
"domain",
"&&",
"hostname",
".",
"IPv6",
"==",
"(",
"version",
"==",
"6",
")",
"{",
"hostnames",
"=",
"append",
"(",
"hostnames",
",",
"hostname",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// FilterByDomainV filters the list of hostnames by domain and IPv4 or IPv6.
// This should never contain more than one item, but returns a list for
// consistency with other filter functions.
//
// This function will panic if IP version is not 4 or 6.
|
[
"FilterByDomainV",
"filters",
"the",
"list",
"of",
"hostnames",
"by",
"domain",
"and",
"IPv4",
"or",
"IPv6",
".",
"This",
"should",
"never",
"contain",
"more",
"than",
"one",
"item",
"but",
"returns",
"a",
"list",
"for",
"consistency",
"with",
"other",
"filter",
"functions",
".",
"This",
"function",
"will",
"panic",
"if",
"IP",
"version",
"is",
"not",
"4",
"or",
"6",
"."
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L338-L348
|
20,219
|
cbednarski/hostess
|
hostlist.go
|
Apply
|
func (h *Hostlist) Apply(jsonbytes []byte) error {
var hostnames Hostlist
err := json.Unmarshal(jsonbytes, &hostnames)
if err != nil {
return err
}
for _, hostname := range hostnames {
h.Add(hostname)
}
return nil
}
|
go
|
func (h *Hostlist) Apply(jsonbytes []byte) error {
var hostnames Hostlist
err := json.Unmarshal(jsonbytes, &hostnames)
if err != nil {
return err
}
for _, hostname := range hostnames {
h.Add(hostname)
}
return nil
}
|
[
"func",
"(",
"h",
"*",
"Hostlist",
")",
"Apply",
"(",
"jsonbytes",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"hostnames",
"Hostlist",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"jsonbytes",
",",
"&",
"hostnames",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"hostname",
":=",
"range",
"hostnames",
"{",
"h",
".",
"Add",
"(",
"hostname",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Apply imports all entries from the JSON input to this Hostlist
|
[
"Apply",
"imports",
"all",
"entries",
"from",
"the",
"JSON",
"input",
"to",
"this",
"Hostlist"
] |
4c91c5787547219e13bce8e17bd1d0049e3918e6
|
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostlist.go#L425-L437
|
20,220
|
uber-common/bark
|
internal/callerskiphelper/callerskiphelper.go
|
LogWithBarker
|
func LogWithBarker(b bark.Logger, msg string) {
b.Error(fmt.Sprintf("logged from helper: %s", msg))
}
|
go
|
func LogWithBarker(b bark.Logger, msg string) {
b.Error(fmt.Sprintf("logged from helper: %s", msg))
}
|
[
"func",
"LogWithBarker",
"(",
"b",
"bark",
".",
"Logger",
",",
"msg",
"string",
")",
"{",
"b",
".",
"Error",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
")",
"\n",
"}"
] |
// LogWithBarker emits a log entry using a bark logger.
|
[
"LogWithBarker",
"emits",
"a",
"log",
"entry",
"using",
"a",
"bark",
"logger",
"."
] |
362cbdc2431a7f2414126b4fb4914820b876fad4
|
https://github.com/uber-common/bark/blob/362cbdc2431a7f2414126b4fb4914820b876fad4/internal/callerskiphelper/callerskiphelper.go#L12-L14
|
20,221
|
uber-common/bark
|
internal/callerskiphelper/callerskiphelper.go
|
LogWithZapper
|
func LogWithZapper(z *zap.Logger, msg string) {
z.Error(fmt.Sprintf("logged from helper: %s", msg))
}
|
go
|
func LogWithZapper(z *zap.Logger, msg string) {
z.Error(fmt.Sprintf("logged from helper: %s", msg))
}
|
[
"func",
"LogWithZapper",
"(",
"z",
"*",
"zap",
".",
"Logger",
",",
"msg",
"string",
")",
"{",
"z",
".",
"Error",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
")",
"\n",
"}"
] |
// LogWithZapper emits a log entry using a zap logger.
|
[
"LogWithZapper",
"emits",
"a",
"log",
"entry",
"using",
"a",
"zap",
"logger",
"."
] |
362cbdc2431a7f2414126b4fb4914820b876fad4
|
https://github.com/uber-common/bark/blob/362cbdc2431a7f2414126b4fb4914820b876fad4/internal/callerskiphelper/callerskiphelper.go#L17-L19
|
20,222
|
uber-common/bark
|
interface.go
|
NewNopLogger
|
func NewNopLogger() Logger {
return NewLoggerFromLogrus(&logrus.Logger{
Out: ioutil.Discard,
Formatter: new(logrus.JSONFormatter),
Level: logrus.DebugLevel,
})
}
|
go
|
func NewNopLogger() Logger {
return NewLoggerFromLogrus(&logrus.Logger{
Out: ioutil.Discard,
Formatter: new(logrus.JSONFormatter),
Level: logrus.DebugLevel,
})
}
|
[
"func",
"NewNopLogger",
"(",
")",
"Logger",
"{",
"return",
"NewLoggerFromLogrus",
"(",
"&",
"logrus",
".",
"Logger",
"{",
"Out",
":",
"ioutil",
".",
"Discard",
",",
"Formatter",
":",
"new",
"(",
"logrus",
".",
"JSONFormatter",
")",
",",
"Level",
":",
"logrus",
".",
"DebugLevel",
",",
"}",
")",
"\n",
"}"
] |
// NewNopLogger creates a no-op logger.
|
[
"NewNopLogger",
"creates",
"a",
"no",
"-",
"op",
"logger",
"."
] |
362cbdc2431a7f2414126b4fb4914820b876fad4
|
https://github.com/uber-common/bark/blob/362cbdc2431a7f2414126b4fb4914820b876fad4/interface.go#L106-L112
|
20,223
|
uber-common/bark
|
zbark/barkify.go
|
Barkify
|
func Barkify(l *zap.Logger) bark.Logger {
if z, ok := l.Core().(*zapper); ok {
return z.l
}
return barker{l.WithOptions(zap.AddCallerSkip(_barkifyCallerSkip)).Sugar()}
}
|
go
|
func Barkify(l *zap.Logger) bark.Logger {
if z, ok := l.Core().(*zapper); ok {
return z.l
}
return barker{l.WithOptions(zap.AddCallerSkip(_barkifyCallerSkip)).Sugar()}
}
|
[
"func",
"Barkify",
"(",
"l",
"*",
"zap",
".",
"Logger",
")",
"bark",
".",
"Logger",
"{",
"if",
"z",
",",
"ok",
":=",
"l",
".",
"Core",
"(",
")",
".",
"(",
"*",
"zapper",
")",
";",
"ok",
"{",
"return",
"z",
".",
"l",
"\n",
"}",
"\n",
"return",
"barker",
"{",
"l",
".",
"WithOptions",
"(",
"zap",
".",
"AddCallerSkip",
"(",
"_barkifyCallerSkip",
")",
")",
".",
"Sugar",
"(",
")",
"}",
"\n",
"}"
] |
// Barkify wraps a zap logger in a compatibility layer so that it satisfies
// the bark.Logger interface. Note that the wrapper always returns nil from
// the Fields method, since zap doesn't support this functionality.
|
[
"Barkify",
"wraps",
"a",
"zap",
"logger",
"in",
"a",
"compatibility",
"layer",
"so",
"that",
"it",
"satisfies",
"the",
"bark",
".",
"Logger",
"interface",
".",
"Note",
"that",
"the",
"wrapper",
"always",
"returns",
"nil",
"from",
"the",
"Fields",
"method",
"since",
"zap",
"doesn",
"t",
"support",
"this",
"functionality",
"."
] |
362cbdc2431a7f2414126b4fb4914820b876fad4
|
https://github.com/uber-common/bark/blob/362cbdc2431a7f2414126b4fb4914820b876fad4/zbark/barkify.go#L32-L37
|
20,224
|
hashicorp/atlas-go
|
archive/archive.go
|
IsSet
|
func (o *ArchiveOpts) IsSet() bool {
return len(o.Exclude) > 0 || len(o.Include) > 0 || o.VCS
}
|
go
|
func (o *ArchiveOpts) IsSet() bool {
return len(o.Exclude) > 0 || len(o.Include) > 0 || o.VCS
}
|
[
"func",
"(",
"o",
"*",
"ArchiveOpts",
")",
"IsSet",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"o",
".",
"Exclude",
")",
">",
"0",
"||",
"len",
"(",
"o",
".",
"Include",
")",
">",
"0",
"||",
"o",
".",
"VCS",
"\n",
"}"
] |
// IsSet says whether any options were set.
|
[
"IsSet",
"says",
"whether",
"any",
"options",
"were",
"set",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/archive.go#L49-L51
|
20,225
|
hashicorp/atlas-go
|
archive/archive.go
|
CreateArchive
|
func CreateArchive(path string, opts *ArchiveOpts) (*Archive, error) {
log.Printf("[INFO] creating archive from %s", path)
// Dereference any symlinks and determine the real path and info
fi, err := os.Lstat(path)
if err != nil {
return nil, err
}
if fi.Mode()&os.ModeSymlink != 0 {
path, fi, err = readLinkFull(path, fi)
if err != nil {
return nil, err
}
}
// Windows
path = filepath.ToSlash(path)
// Direct file paths cannot have archive options
if !fi.IsDir() && opts.IsSet() {
return nil, fmt.Errorf(
"options such as exclude, include, and VCS can't be set when " +
"the path is a file.")
}
if fi.IsDir() {
return archiveDir(path, opts)
} else {
return archiveFile(path)
}
}
|
go
|
func CreateArchive(path string, opts *ArchiveOpts) (*Archive, error) {
log.Printf("[INFO] creating archive from %s", path)
// Dereference any symlinks and determine the real path and info
fi, err := os.Lstat(path)
if err != nil {
return nil, err
}
if fi.Mode()&os.ModeSymlink != 0 {
path, fi, err = readLinkFull(path, fi)
if err != nil {
return nil, err
}
}
// Windows
path = filepath.ToSlash(path)
// Direct file paths cannot have archive options
if !fi.IsDir() && opts.IsSet() {
return nil, fmt.Errorf(
"options such as exclude, include, and VCS can't be set when " +
"the path is a file.")
}
if fi.IsDir() {
return archiveDir(path, opts)
} else {
return archiveFile(path)
}
}
|
[
"func",
"CreateArchive",
"(",
"path",
"string",
",",
"opts",
"*",
"ArchiveOpts",
")",
"(",
"*",
"Archive",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n\n",
"// Dereference any symlinks and determine the real path and info",
"fi",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"fi",
".",
"Mode",
"(",
")",
"&",
"os",
".",
"ModeSymlink",
"!=",
"0",
"{",
"path",
",",
"fi",
",",
"err",
"=",
"readLinkFull",
"(",
"path",
",",
"fi",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Windows",
"path",
"=",
"filepath",
".",
"ToSlash",
"(",
"path",
")",
"\n\n",
"// Direct file paths cannot have archive options",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"&&",
"opts",
".",
"IsSet",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"archiveDir",
"(",
"path",
",",
"opts",
")",
"\n",
"}",
"else",
"{",
"return",
"archiveFile",
"(",
"path",
")",
"\n",
"}",
"\n",
"}"
] |
// CreateArchive takes the given path and ArchiveOpts and archives it.
//
// The archive will be fully completed and put into a temporary file.
// This must be done to retrieve the content length of the archive which
// is needed for almost all operations involving archives with Atlas. Because
// of this, sufficient disk space will be required to buffer the archive.
|
[
"CreateArchive",
"takes",
"the",
"given",
"path",
"and",
"ArchiveOpts",
"and",
"archives",
"it",
".",
"The",
"archive",
"will",
"be",
"fully",
"completed",
"and",
"put",
"into",
"a",
"temporary",
"file",
".",
"This",
"must",
"be",
"done",
"to",
"retrieve",
"the",
"content",
"length",
"of",
"the",
"archive",
"which",
"is",
"needed",
"for",
"almost",
"all",
"operations",
"involving",
"archives",
"with",
"Atlas",
".",
"Because",
"of",
"this",
"sufficient",
"disk",
"space",
"will",
"be",
"required",
"to",
"buffer",
"the",
"archive",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/archive.go#L65-L95
|
20,226
|
hashicorp/atlas-go
|
v1/application.go
|
CreateApp
|
func (c *Client) CreateApp(user, name string) (*App, error) {
log.Printf("[INFO] creating application %s/%s", user, name)
body, err := json.Marshal(&appWrapper{&App{
User: user,
Name: name,
}})
if err != nil {
return nil, err
}
endpoint := "/api/v1/vagrant/applications"
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var app App
if err := decodeJSON(response, &app); err != nil {
return nil, err
}
return &app, nil
}
|
go
|
func (c *Client) CreateApp(user, name string) (*App, error) {
log.Printf("[INFO] creating application %s/%s", user, name)
body, err := json.Marshal(&appWrapper{&App{
User: user,
Name: name,
}})
if err != nil {
return nil, err
}
endpoint := "/api/v1/vagrant/applications"
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var app App
if err := decodeJSON(response, &app); err != nil {
return nil, err
}
return &app, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CreateApp",
"(",
"user",
",",
"name",
"string",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"appWrapper",
"{",
"&",
"App",
"{",
"User",
":",
"user",
",",
"Name",
":",
"name",
",",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"endpoint",
":=",
"\"",
"\"",
"\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"app",
"App",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"app",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"app",
",",
"nil",
"\n",
"}"
] |
// CreateApp creates a new App under the given user with the given name. If the
// App is created successfully, it is returned. If the server returns any
// errors, an error is returned.
|
[
"CreateApp",
"creates",
"a",
"new",
"App",
"under",
"the",
"given",
"user",
"with",
"the",
"given",
"name",
".",
"If",
"the",
"App",
"is",
"created",
"successfully",
"it",
"is",
"returned",
".",
"If",
"the",
"server",
"returns",
"any",
"errors",
"an",
"error",
"is",
"returned",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/application.go#L58-L91
|
20,227
|
hashicorp/atlas-go
|
v1/application.go
|
UploadApp
|
func (c *Client) UploadApp(app *App, metadata map[string]interface{},
data io.Reader, size int64) (uint64, error) {
log.Printf("[INFO] uploading application %s (%d bytes) with metadata %q",
app.Slug(), size, metadata)
endpoint := fmt.Sprintf("/api/v1/vagrant/applications/%s/%s/versions",
app.User, app.Name)
// If metadata was given, setup the RequestOptions to pass in the metadata
// with the request.
var ro *RequestOptions
if metadata != nil {
// wrap the struct into the correct JSON format
wrapper := struct {
Application *appMetadataWrapper `json:"application"`
}{
&appMetadataWrapper{metadata},
}
m, err := json.Marshal(wrapper)
if err != nil {
return 0, err
}
// Create the request options.
ro = &RequestOptions{
Body: bytes.NewReader(m),
BodyLength: int64(len(m)),
}
}
request, err := c.Request("POST", endpoint, ro)
if err != nil {
return 0, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return 0, err
}
var av appVersion
if err := decodeJSON(response, &av); err != nil {
return 0, err
}
if err := c.putFile(av.UploadPath, data, size); err != nil {
return 0, err
}
return av.Version, nil
}
|
go
|
func (c *Client) UploadApp(app *App, metadata map[string]interface{},
data io.Reader, size int64) (uint64, error) {
log.Printf("[INFO] uploading application %s (%d bytes) with metadata %q",
app.Slug(), size, metadata)
endpoint := fmt.Sprintf("/api/v1/vagrant/applications/%s/%s/versions",
app.User, app.Name)
// If metadata was given, setup the RequestOptions to pass in the metadata
// with the request.
var ro *RequestOptions
if metadata != nil {
// wrap the struct into the correct JSON format
wrapper := struct {
Application *appMetadataWrapper `json:"application"`
}{
&appMetadataWrapper{metadata},
}
m, err := json.Marshal(wrapper)
if err != nil {
return 0, err
}
// Create the request options.
ro = &RequestOptions{
Body: bytes.NewReader(m),
BodyLength: int64(len(m)),
}
}
request, err := c.Request("POST", endpoint, ro)
if err != nil {
return 0, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return 0, err
}
var av appVersion
if err := decodeJSON(response, &av); err != nil {
return 0, err
}
if err := c.putFile(av.UploadPath, data, size); err != nil {
return 0, err
}
return av.Version, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"UploadApp",
"(",
"app",
"*",
"App",
",",
"metadata",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"data",
"io",
".",
"Reader",
",",
"size",
"int64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"app",
".",
"Slug",
"(",
")",
",",
"size",
",",
"metadata",
")",
"\n\n",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"app",
".",
"User",
",",
"app",
".",
"Name",
")",
"\n\n",
"// If metadata was given, setup the RequestOptions to pass in the metadata",
"// with the request.",
"var",
"ro",
"*",
"RequestOptions",
"\n",
"if",
"metadata",
"!=",
"nil",
"{",
"// wrap the struct into the correct JSON format",
"wrapper",
":=",
"struct",
"{",
"Application",
"*",
"appMetadataWrapper",
"`json:\"application\"`",
"\n",
"}",
"{",
"&",
"appMetadataWrapper",
"{",
"metadata",
"}",
",",
"}",
"\n",
"m",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"wrapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// Create the request options.",
"ro",
"=",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"m",
")",
",",
"BodyLength",
":",
"int64",
"(",
"len",
"(",
"m",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"ro",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"av",
"appVersion",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"av",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"putFile",
"(",
"av",
".",
"UploadPath",
",",
"data",
",",
"size",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"av",
".",
"Version",
",",
"nil",
"\n",
"}"
] |
// UploadApp creates and uploads a new version for the App. If the server does not
// find the application, an error is returned. If the server does not accept the
// data, an error is returned.
//
// It is the responsibility of the caller to create a properly-formed data
// object; this method blindly passes along the contents of the io.Reader.
|
[
"UploadApp",
"creates",
"and",
"uploads",
"a",
"new",
"version",
"for",
"the",
"App",
".",
"If",
"the",
"server",
"does",
"not",
"find",
"the",
"application",
"an",
"error",
"is",
"returned",
".",
"If",
"the",
"server",
"does",
"not",
"accept",
"the",
"data",
"an",
"error",
"is",
"returned",
".",
"It",
"is",
"the",
"responsibility",
"of",
"the",
"caller",
"to",
"create",
"a",
"properly",
"-",
"formed",
"data",
"object",
";",
"this",
"method",
"blindly",
"passes",
"along",
"the",
"contents",
"of",
"the",
"io",
".",
"Reader",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/application.go#L113-L164
|
20,228
|
hashicorp/atlas-go
|
v1/client.go
|
DefaultClient
|
func DefaultClient() *Client {
atlasEndpoint := os.Getenv(atlasEndpointEnvVar)
if atlasEndpoint == "" {
atlasEndpoint = atlasDefaultEndpoint
}
client, err := NewClient(atlasEndpoint)
if err != nil {
panic(err)
}
return client
}
|
go
|
func DefaultClient() *Client {
atlasEndpoint := os.Getenv(atlasEndpointEnvVar)
if atlasEndpoint == "" {
atlasEndpoint = atlasDefaultEndpoint
}
client, err := NewClient(atlasEndpoint)
if err != nil {
panic(err)
}
return client
}
|
[
"func",
"DefaultClient",
"(",
")",
"*",
"Client",
"{",
"atlasEndpoint",
":=",
"os",
".",
"Getenv",
"(",
"atlasEndpointEnvVar",
")",
"\n",
"if",
"atlasEndpoint",
"==",
"\"",
"\"",
"{",
"atlasEndpoint",
"=",
"atlasDefaultEndpoint",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"NewClient",
"(",
"atlasEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"client",
"\n",
"}"
] |
// DefaultClient returns a client that connects to the Atlas API.
|
[
"DefaultClient",
"returns",
"a",
"client",
"that",
"connects",
"to",
"the",
"Atlas",
"API",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/client.go#L85-L97
|
20,229
|
hashicorp/atlas-go
|
v1/client.go
|
Request
|
func (c *Client) Request(verb, spath string, ro *RequestOptions) (*http.Request, error) {
log.Printf("[INFO] request: %s %s", verb, spath)
// Ensure we have a RequestOptions struct (passing nil is an acceptable)
if ro == nil {
ro = new(RequestOptions)
}
// Create a new URL with the appended path
u := *c.URL
u.Path = path.Join(c.URL.Path, spath)
// Add the token and other params
if c.Token != "" {
log.Printf("[DEBUG] request: appending token (%s)", maskString(c.Token))
if ro.Headers == nil {
ro.Headers = make(map[string]string)
}
ro.Headers[atlasTokenHeader] = c.Token
}
return c.rawRequest(verb, &u, ro)
}
|
go
|
func (c *Client) Request(verb, spath string, ro *RequestOptions) (*http.Request, error) {
log.Printf("[INFO] request: %s %s", verb, spath)
// Ensure we have a RequestOptions struct (passing nil is an acceptable)
if ro == nil {
ro = new(RequestOptions)
}
// Create a new URL with the appended path
u := *c.URL
u.Path = path.Join(c.URL.Path, spath)
// Add the token and other params
if c.Token != "" {
log.Printf("[DEBUG] request: appending token (%s)", maskString(c.Token))
if ro.Headers == nil {
ro.Headers = make(map[string]string)
}
ro.Headers[atlasTokenHeader] = c.Token
}
return c.rawRequest(verb, &u, ro)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Request",
"(",
"verb",
",",
"spath",
"string",
",",
"ro",
"*",
"RequestOptions",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"verb",
",",
"spath",
")",
"\n\n",
"// Ensure we have a RequestOptions struct (passing nil is an acceptable)",
"if",
"ro",
"==",
"nil",
"{",
"ro",
"=",
"new",
"(",
"RequestOptions",
")",
"\n",
"}",
"\n\n",
"// Create a new URL with the appended path",
"u",
":=",
"*",
"c",
".",
"URL",
"\n",
"u",
".",
"Path",
"=",
"path",
".",
"Join",
"(",
"c",
".",
"URL",
".",
"Path",
",",
"spath",
")",
"\n\n",
"// Add the token and other params",
"if",
"c",
".",
"Token",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"maskString",
"(",
"c",
".",
"Token",
")",
")",
"\n",
"if",
"ro",
".",
"Headers",
"==",
"nil",
"{",
"ro",
".",
"Headers",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n\n",
"ro",
".",
"Headers",
"[",
"atlasTokenHeader",
"]",
"=",
"c",
".",
"Token",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"rawRequest",
"(",
"verb",
",",
"&",
"u",
",",
"ro",
")",
"\n",
"}"
] |
// Request creates a new HTTP request using the given verb and sub path.
|
[
"Request",
"creates",
"a",
"new",
"HTTP",
"request",
"using",
"the",
"given",
"verb",
"and",
"sub",
"path",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/client.go#L169-L192
|
20,230
|
hashicorp/atlas-go
|
v1/client.go
|
rawRequest
|
func (c *Client) rawRequest(verb string, u *url.URL, ro *RequestOptions) (*http.Request, error) {
if verb == "" {
return nil, fmt.Errorf("client: missing verb")
}
if u == nil {
return nil, fmt.Errorf("client: missing URL.url")
}
if ro == nil {
return nil, fmt.Errorf("client: missing RequestOptions")
}
// Add the token and other params
var params = make(url.Values)
for k, v := range ro.Params {
params.Add(k, v)
}
u.RawQuery = params.Encode()
// Create the request object
request, err := http.NewRequest(verb, u.String(), ro.Body)
if err != nil {
return nil, err
}
// set our default headers first
for k, v := range c.DefaultHeader {
request.Header[k] = v
}
// Add any request headers (auth will be here if set)
for k, v := range ro.Headers {
request.Header.Add(k, v)
}
// Add content-length if we have it
if ro.BodyLength > 0 {
request.ContentLength = ro.BodyLength
}
log.Printf("[DEBUG] raw request: %#v", request)
return request, nil
}
|
go
|
func (c *Client) rawRequest(verb string, u *url.URL, ro *RequestOptions) (*http.Request, error) {
if verb == "" {
return nil, fmt.Errorf("client: missing verb")
}
if u == nil {
return nil, fmt.Errorf("client: missing URL.url")
}
if ro == nil {
return nil, fmt.Errorf("client: missing RequestOptions")
}
// Add the token and other params
var params = make(url.Values)
for k, v := range ro.Params {
params.Add(k, v)
}
u.RawQuery = params.Encode()
// Create the request object
request, err := http.NewRequest(verb, u.String(), ro.Body)
if err != nil {
return nil, err
}
// set our default headers first
for k, v := range c.DefaultHeader {
request.Header[k] = v
}
// Add any request headers (auth will be here if set)
for k, v := range ro.Headers {
request.Header.Add(k, v)
}
// Add content-length if we have it
if ro.BodyLength > 0 {
request.ContentLength = ro.BodyLength
}
log.Printf("[DEBUG] raw request: %#v", request)
return request, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"rawRequest",
"(",
"verb",
"string",
",",
"u",
"*",
"url",
".",
"URL",
",",
"ro",
"*",
"RequestOptions",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"if",
"verb",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"u",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"ro",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Add the token and other params",
"var",
"params",
"=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"ro",
".",
"Params",
"{",
"params",
".",
"Add",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"u",
".",
"RawQuery",
"=",
"params",
".",
"Encode",
"(",
")",
"\n\n",
"// Create the request object",
"request",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"verb",
",",
"u",
".",
"String",
"(",
")",
",",
"ro",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// set our default headers first",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"DefaultHeader",
"{",
"request",
".",
"Header",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// Add any request headers (auth will be here if set)",
"for",
"k",
",",
"v",
":=",
"range",
"ro",
".",
"Headers",
"{",
"request",
".",
"Header",
".",
"Add",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n\n",
"// Add content-length if we have it",
"if",
"ro",
".",
"BodyLength",
">",
"0",
"{",
"request",
".",
"ContentLength",
"=",
"ro",
".",
"BodyLength",
"\n",
"}",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"request",
")",
"\n\n",
"return",
"request",
",",
"nil",
"\n",
"}"
] |
// rawRequest accepts a verb, URL, and RequestOptions struct and returns the
// constructed http.Request and any errors that occurred
|
[
"rawRequest",
"accepts",
"a",
"verb",
"URL",
"and",
"RequestOptions",
"struct",
"and",
"returns",
"the",
"constructed",
"http",
".",
"Request",
"and",
"any",
"errors",
"that",
"occurred"
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/client.go#L219-L263
|
20,231
|
hashicorp/atlas-go
|
v1/client.go
|
parseErr
|
func parseErr(r *http.Response) error {
re := &RailsError{}
if err := decodeJSON(r, &re); err != nil {
return fmt.Errorf("error decoding JSON body: %s", err)
}
return re
}
|
go
|
func parseErr(r *http.Response) error {
re := &RailsError{}
if err := decodeJSON(r, &re); err != nil {
return fmt.Errorf("error decoding JSON body: %s", err)
}
return re
}
|
[
"func",
"parseErr",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"re",
":=",
"&",
"RailsError",
"{",
"}",
"\n\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"r",
",",
"&",
"re",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"re",
"\n",
"}"
] |
// parseErr is used to take an error JSON response and return a single string
// for use in error messages.
|
[
"parseErr",
"is",
"used",
"to",
"take",
"an",
"error",
"JSON",
"response",
"and",
"return",
"a",
"single",
"string",
"for",
"use",
"in",
"error",
"messages",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/client.go#L312-L320
|
20,232
|
hashicorp/atlas-go
|
v1/build_config.go
|
BuildConfig
|
func (c *Client) BuildConfig(user, name string) (*BuildConfig, error) {
log.Printf("[INFO] getting build configuration %s/%s", user, name)
endpoint := fmt.Sprintf("/api/v1/packer/build-configurations/%s/%s", user, name)
request, err := c.Request("GET", endpoint, nil)
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var bc BuildConfig
if err := decodeJSON(response, &bc); err != nil {
return nil, err
}
return &bc, nil
}
|
go
|
func (c *Client) BuildConfig(user, name string) (*BuildConfig, error) {
log.Printf("[INFO] getting build configuration %s/%s", user, name)
endpoint := fmt.Sprintf("/api/v1/packer/build-configurations/%s/%s", user, name)
request, err := c.Request("GET", endpoint, nil)
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var bc BuildConfig
if err := decodeJSON(response, &bc); err != nil {
return nil, err
}
return &bc, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"BuildConfig",
"(",
"user",
",",
"name",
"string",
")",
"(",
"*",
"BuildConfig",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n\n",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"bc",
"BuildConfig",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"bc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"bc",
",",
"nil",
"\n",
"}"
] |
// BuildConfig gets a single build configuration by user and name.
|
[
"BuildConfig",
"gets",
"a",
"single",
"build",
"configuration",
"by",
"user",
"and",
"name",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/build_config.go#L72-L92
|
20,233
|
hashicorp/atlas-go
|
v1/build_config.go
|
CreateBuildConfig
|
func (c *Client) CreateBuildConfig(user, name string) (*BuildConfig, error) {
log.Printf("[INFO] creating build configuration %s/%s", user, name)
endpoint := "/api/v1/packer/build-configurations"
body, err := json.Marshal(&bcWrapper{
BuildConfig: &BuildConfig{
User: user,
Name: name,
},
})
if err != nil {
return nil, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var bc BuildConfig
if err := decodeJSON(response, &bc); err != nil {
return nil, err
}
return &bc, nil
}
|
go
|
func (c *Client) CreateBuildConfig(user, name string) (*BuildConfig, error) {
log.Printf("[INFO] creating build configuration %s/%s", user, name)
endpoint := "/api/v1/packer/build-configurations"
body, err := json.Marshal(&bcWrapper{
BuildConfig: &BuildConfig{
User: user,
Name: name,
},
})
if err != nil {
return nil, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var bc BuildConfig
if err := decodeJSON(response, &bc); err != nil {
return nil, err
}
return &bc, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CreateBuildConfig",
"(",
"user",
",",
"name",
"string",
")",
"(",
"*",
"BuildConfig",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n\n",
"endpoint",
":=",
"\"",
"\"",
"\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"bcWrapper",
"{",
"BuildConfig",
":",
"&",
"BuildConfig",
"{",
"User",
":",
"user",
",",
"Name",
":",
"name",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"bc",
"BuildConfig",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"bc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"bc",
",",
"nil",
"\n",
"}"
] |
// CreateBuildConfig creates a new build configuration.
|
[
"CreateBuildConfig",
"creates",
"a",
"new",
"build",
"configuration",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/build_config.go#L95-L130
|
20,234
|
hashicorp/atlas-go
|
v1/artifact.go
|
MarshalJSON
|
func (o *UploadArtifactOpts) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"artifact_version": map[string]interface{}{
"id": o.ID,
"file": o.File != nil,
"metadata": o.Metadata,
"build_id": o.BuildID,
"compile_id": o.CompileID,
},
})
}
|
go
|
func (o *UploadArtifactOpts) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"artifact_version": map[string]interface{}{
"id": o.ID,
"file": o.File != nil,
"metadata": o.Metadata,
"build_id": o.BuildID,
"compile_id": o.CompileID,
},
})
}
|
[
"func",
"(",
"o",
"*",
"UploadArtifactOpts",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"o",
".",
"ID",
",",
"\"",
"\"",
":",
"o",
".",
"File",
"!=",
"nil",
",",
"\"",
"\"",
":",
"o",
".",
"Metadata",
",",
"\"",
"\"",
":",
"o",
".",
"BuildID",
",",
"\"",
"\"",
":",
"o",
".",
"CompileID",
",",
"}",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON converts the UploadArtifactOpts into a JSON struct.
|
[
"MarshalJSON",
"converts",
"the",
"UploadArtifactOpts",
"into",
"a",
"JSON",
"struct",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L62-L72
|
20,235
|
hashicorp/atlas-go
|
v1/artifact.go
|
Artifact
|
func (c *Client) Artifact(user, name string) (*Artifact, error) {
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s", user, name)
request, err := c.Request("GET", endpoint, nil)
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var aw artifactWrapper
if err := decodeJSON(response, &aw); err != nil {
return nil, err
}
return aw.Artifact, nil
}
|
go
|
func (c *Client) Artifact(user, name string) (*Artifact, error) {
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s", user, name)
request, err := c.Request("GET", endpoint, nil)
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var aw artifactWrapper
if err := decodeJSON(response, &aw); err != nil {
return nil, err
}
return aw.Artifact, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Artifact",
"(",
"user",
",",
"name",
"string",
")",
"(",
"*",
"Artifact",
",",
"error",
")",
"{",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"aw",
"artifactWrapper",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"aw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"aw",
".",
"Artifact",
",",
"nil",
"\n",
"}"
] |
// Artifact finds the Atlas artifact by the given name and returns it. Any
// errors that occur are returned, including ErrAuth and ErrNotFound special
// exceptions which the user may want to handle separately.
|
[
"Artifact",
"finds",
"the",
"Atlas",
"artifact",
"by",
"the",
"given",
"name",
"and",
"returns",
"it",
".",
"Any",
"errors",
"that",
"occur",
"are",
"returned",
"including",
"ErrAuth",
"and",
"ErrNotFound",
"special",
"exceptions",
"which",
"the",
"user",
"may",
"want",
"to",
"handle",
"separately",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L81-L99
|
20,236
|
hashicorp/atlas-go
|
v1/artifact.go
|
ArtifactSearch
|
func (c *Client) ArtifactSearch(opts *ArtifactSearchOpts) ([]*ArtifactVersion, error) {
log.Printf("[INFO] searching artifacts: %#v", opts)
params := make(map[string]string)
if opts.Version != "" {
params["version"] = opts.Version
}
if opts.Build != "" {
params["build"] = opts.Build
}
i := 1
for k, v := range opts.Metadata {
prefix := fmt.Sprintf("metadata.%d.", i)
params[prefix+"key"] = k
if v != MetadataAnyValue {
params[prefix+"value"] = v
}
i++
}
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s/%s/search",
opts.User, opts.Name, opts.Type)
request, err := c.Request("GET", endpoint, &RequestOptions{
Params: params,
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var w artifactSearchWrapper
if err := decodeJSON(response, &w); err != nil {
return nil, err
}
return w.Versions, nil
}
|
go
|
func (c *Client) ArtifactSearch(opts *ArtifactSearchOpts) ([]*ArtifactVersion, error) {
log.Printf("[INFO] searching artifacts: %#v", opts)
params := make(map[string]string)
if opts.Version != "" {
params["version"] = opts.Version
}
if opts.Build != "" {
params["build"] = opts.Build
}
i := 1
for k, v := range opts.Metadata {
prefix := fmt.Sprintf("metadata.%d.", i)
params[prefix+"key"] = k
if v != MetadataAnyValue {
params[prefix+"value"] = v
}
i++
}
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s/%s/search",
opts.User, opts.Name, opts.Type)
request, err := c.Request("GET", endpoint, &RequestOptions{
Params: params,
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var w artifactSearchWrapper
if err := decodeJSON(response, &w); err != nil {
return nil, err
}
return w.Versions, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ArtifactSearch",
"(",
"opts",
"*",
"ArtifactSearchOpts",
")",
"(",
"[",
"]",
"*",
"ArtifactVersion",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"opts",
")",
"\n\n",
"params",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"opts",
".",
"Version",
"!=",
"\"",
"\"",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"opts",
".",
"Version",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Build",
"!=",
"\"",
"\"",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"opts",
".",
"Build",
"\n",
"}",
"\n\n",
"i",
":=",
"1",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"opts",
".",
"Metadata",
"{",
"prefix",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"params",
"[",
"prefix",
"+",
"\"",
"\"",
"]",
"=",
"k",
"\n",
"if",
"v",
"!=",
"MetadataAnyValue",
"{",
"params",
"[",
"prefix",
"+",
"\"",
"\"",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"i",
"++",
"\n",
"}",
"\n\n",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"User",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Type",
")",
"\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Params",
":",
"params",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"w",
"artifactSearchWrapper",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Versions",
",",
"nil",
"\n",
"}"
] |
// ArtifactSearch searches Atlas for the given ArtifactSearchOpts and returns
// a slice of ArtifactVersions.
|
[
"ArtifactSearch",
"searches",
"Atlas",
"for",
"the",
"given",
"ArtifactSearchOpts",
"and",
"returns",
"a",
"slice",
"of",
"ArtifactVersions",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L103-L145
|
20,237
|
hashicorp/atlas-go
|
v1/artifact.go
|
CreateArtifact
|
func (c *Client) CreateArtifact(user, name string) (*Artifact, error) {
log.Printf("[INFO] creating artifact: %s/%s", user, name)
body, err := json.Marshal(&artifactWrapper{&Artifact{
User: user,
Name: name,
}})
if err != nil {
return nil, err
}
endpoint := "/api/v1/artifacts"
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var aw artifactWrapper
if err := decodeJSON(response, &aw); err != nil {
return nil, err
}
return aw.Artifact, nil
}
|
go
|
func (c *Client) CreateArtifact(user, name string) (*Artifact, error) {
log.Printf("[INFO] creating artifact: %s/%s", user, name)
body, err := json.Marshal(&artifactWrapper{&Artifact{
User: user,
Name: name,
}})
if err != nil {
return nil, err
}
endpoint := "/api/v1/artifacts"
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var aw artifactWrapper
if err := decodeJSON(response, &aw); err != nil {
return nil, err
}
return aw.Artifact, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CreateArtifact",
"(",
"user",
",",
"name",
"string",
")",
"(",
"*",
"Artifact",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"artifactWrapper",
"{",
"&",
"Artifact",
"{",
"User",
":",
"user",
",",
"Name",
":",
"name",
",",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"endpoint",
":=",
"\"",
"\"",
"\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"aw",
"artifactWrapper",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"aw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"aw",
".",
"Artifact",
",",
"nil",
"\n",
"}"
] |
// CreateArtifact creates and returns a new Artifact in Atlas. Any errors that
// occurr are returned.
|
[
"CreateArtifact",
"creates",
"and",
"returns",
"a",
"new",
"Artifact",
"in",
"Atlas",
".",
"Any",
"errors",
"that",
"occurr",
"are",
"returned",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L149-L181
|
20,238
|
hashicorp/atlas-go
|
v1/artifact.go
|
ArtifactFileURL
|
func (c *Client) ArtifactFileURL(av *ArtifactVersion) (*url.URL, error) {
if !av.File {
return nil, nil
}
u := *c.URL
u.Path = fmt.Sprintf("/api/v1/artifacts/%s/%s/%s/%d/file",
av.User, av.Name, av.Type, av.Version)
return &u, nil
}
|
go
|
func (c *Client) ArtifactFileURL(av *ArtifactVersion) (*url.URL, error) {
if !av.File {
return nil, nil
}
u := *c.URL
u.Path = fmt.Sprintf("/api/v1/artifacts/%s/%s/%s/%d/file",
av.User, av.Name, av.Type, av.Version)
return &u, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ArtifactFileURL",
"(",
"av",
"*",
"ArtifactVersion",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"if",
"!",
"av",
".",
"File",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"u",
":=",
"*",
"c",
".",
"URL",
"\n",
"u",
".",
"Path",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"av",
".",
"User",
",",
"av",
".",
"Name",
",",
"av",
".",
"Type",
",",
"av",
".",
"Version",
")",
"\n",
"return",
"&",
"u",
",",
"nil",
"\n",
"}"
] |
// ArtifactFileURL is a helper method for getting the URL for an ArtifactVersion
// from the Client.
|
[
"ArtifactFileURL",
"is",
"a",
"helper",
"method",
"for",
"getting",
"the",
"URL",
"for",
"an",
"ArtifactVersion",
"from",
"the",
"Client",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L185-L194
|
20,239
|
hashicorp/atlas-go
|
v1/artifact.go
|
UploadArtifact
|
func (c *Client) UploadArtifact(opts *UploadArtifactOpts) (*ArtifactVersion, error) {
log.Printf("[INFO] uploading artifact: %s/%s (%s)", opts.User, opts.Name, opts.Type)
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s/%s",
opts.User, opts.Name, opts.Type)
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var av ArtifactVersion
if err := decodeJSON(response, &av); err != nil {
return nil, err
}
if opts.File != nil {
if err := c.putFile(av.UploadPath, opts.File, opts.FileSize); err != nil {
return nil, err
}
}
return &av, nil
}
|
go
|
func (c *Client) UploadArtifact(opts *UploadArtifactOpts) (*ArtifactVersion, error) {
log.Printf("[INFO] uploading artifact: %s/%s (%s)", opts.User, opts.Name, opts.Type)
endpoint := fmt.Sprintf("/api/v1/artifacts/%s/%s/%s",
opts.User, opts.Name, opts.Type)
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return nil, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return nil, err
}
var av ArtifactVersion
if err := decodeJSON(response, &av); err != nil {
return nil, err
}
if opts.File != nil {
if err := c.putFile(av.UploadPath, opts.File, opts.FileSize); err != nil {
return nil, err
}
}
return &av, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"UploadArtifact",
"(",
"opts",
"*",
"UploadArtifactOpts",
")",
"(",
"*",
"ArtifactVersion",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"opts",
".",
"User",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Type",
")",
"\n\n",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"User",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Type",
")",
"\n\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"av",
"ArtifactVersion",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"av",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"opts",
".",
"File",
"!=",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"putFile",
"(",
"av",
".",
"UploadPath",
",",
"opts",
".",
"File",
",",
"opts",
".",
"FileSize",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"av",
",",
"nil",
"\n",
"}"
] |
// UploadArtifact streams the upload of a file on disk using the given
// UploadArtifactOpts. Any errors that occur are returned.
|
[
"UploadArtifact",
"streams",
"the",
"upload",
"of",
"a",
"file",
"on",
"disk",
"using",
"the",
"given",
"UploadArtifactOpts",
".",
"Any",
"errors",
"that",
"occur",
"are",
"returned",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/artifact.go#L198-L236
|
20,240
|
hashicorp/atlas-go
|
v1/terraform.go
|
CreateTerraformConfigVersion
|
func (c *Client) CreateTerraformConfigVersion(
user string, name string,
version *TerraformConfigVersion,
data io.Reader, size int64) (int, error) {
log.Printf("[INFO] creating terraform configuration %s/%s", user, name)
endpoint := fmt.Sprintf(
"/api/v1/terraform/configurations/%s/%s/versions", user, name)
body, err := json.Marshal(&tfConfigVersionWrapper{
Version: version,
})
if err != nil {
return 0, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return 0, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return 0, err
}
var result tfConfigVersionCreate
if err := decodeJSON(response, &result); err != nil {
return 0, err
}
if err := c.putFile(result.UploadPath, data, size); err != nil {
return 0, err
}
return result.Version, nil
}
|
go
|
func (c *Client) CreateTerraformConfigVersion(
user string, name string,
version *TerraformConfigVersion,
data io.Reader, size int64) (int, error) {
log.Printf("[INFO] creating terraform configuration %s/%s", user, name)
endpoint := fmt.Sprintf(
"/api/v1/terraform/configurations/%s/%s/versions", user, name)
body, err := json.Marshal(&tfConfigVersionWrapper{
Version: version,
})
if err != nil {
return 0, err
}
request, err := c.Request("POST", endpoint, &RequestOptions{
Body: bytes.NewReader(body),
Headers: map[string]string{
"Content-Type": "application/json",
},
})
if err != nil {
return 0, err
}
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return 0, err
}
var result tfConfigVersionCreate
if err := decodeJSON(response, &result); err != nil {
return 0, err
}
if err := c.putFile(result.UploadPath, data, size); err != nil {
return 0, err
}
return result.Version, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CreateTerraformConfigVersion",
"(",
"user",
"string",
",",
"name",
"string",
",",
"version",
"*",
"TerraformConfigVersion",
",",
"data",
"io",
".",
"Reader",
",",
"size",
"int64",
")",
"(",
"int",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n\n",
"endpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"user",
",",
"name",
")",
"\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"tfConfigVersionWrapper",
"{",
"Version",
":",
"version",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"result",
"tfConfigVersionCreate",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"putFile",
"(",
"result",
".",
"UploadPath",
",",
"data",
",",
"size",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
".",
"Version",
",",
"nil",
"\n",
"}"
] |
// CreateTerraformConfigVersion creatse a new Terraform configuration
// versions and uploads a slug with it.
|
[
"CreateTerraformConfigVersion",
"creatse",
"a",
"new",
"Terraform",
"configuration",
"versions",
"and",
"uploads",
"a",
"slug",
"with",
"it",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/terraform.go#L57-L97
|
20,241
|
hashicorp/atlas-go
|
v1/authentication.go
|
Login
|
func (c *Client) Login(username, password string) (string, error) {
log.Printf("[INFO] logging in user %s", username)
if len(username) == 0 {
return "", fmt.Errorf("client: missing username")
}
if len(password) == 0 {
return "", fmt.Errorf("client: missing password")
}
// Make a request
request, err := c.Request("POST", "/api/v1/authenticate", &RequestOptions{
Body: strings.NewReader(url.Values{
"user[login]": []string{username},
"user[password]": []string{password},
"user[description]": []string{"Created by the Atlas Go Client"},
}.Encode()),
Headers: map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
},
})
if err != nil {
return "", err
}
// Make the request
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return "", err
}
// Decode the body
var tResponse struct{ Token string }
if err := decodeJSON(response, &tResponse); err != nil {
return "", nil
}
// Set the token
log.Printf("[DEBUG] setting atlas token (%s)", maskString(tResponse.Token))
c.Token = tResponse.Token
// Return the token
return c.Token, nil
}
|
go
|
func (c *Client) Login(username, password string) (string, error) {
log.Printf("[INFO] logging in user %s", username)
if len(username) == 0 {
return "", fmt.Errorf("client: missing username")
}
if len(password) == 0 {
return "", fmt.Errorf("client: missing password")
}
// Make a request
request, err := c.Request("POST", "/api/v1/authenticate", &RequestOptions{
Body: strings.NewReader(url.Values{
"user[login]": []string{username},
"user[password]": []string{password},
"user[description]": []string{"Created by the Atlas Go Client"},
}.Encode()),
Headers: map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
},
})
if err != nil {
return "", err
}
// Make the request
response, err := checkResp(c.HTTPClient.Do(request))
if err != nil {
return "", err
}
// Decode the body
var tResponse struct{ Token string }
if err := decodeJSON(response, &tResponse); err != nil {
return "", nil
}
// Set the token
log.Printf("[DEBUG] setting atlas token (%s)", maskString(tResponse.Token))
c.Token = tResponse.Token
// Return the token
return c.Token, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Login",
"(",
"username",
",",
"password",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"username",
")",
"\n\n",
"if",
"len",
"(",
"username",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"password",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Make a request",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"RequestOptions",
"{",
"Body",
":",
"strings",
".",
"NewReader",
"(",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"username",
"}",
",",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"password",
"}",
",",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
".",
"Encode",
"(",
")",
")",
",",
"Headers",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Make the request",
"response",
",",
"err",
":=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Decode the body",
"var",
"tResponse",
"struct",
"{",
"Token",
"string",
"}",
"\n",
"if",
"err",
":=",
"decodeJSON",
"(",
"response",
",",
"&",
"tResponse",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"// Set the token",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"maskString",
"(",
"tResponse",
".",
"Token",
")",
")",
"\n",
"c",
".",
"Token",
"=",
"tResponse",
".",
"Token",
"\n\n",
"// Return the token",
"return",
"c",
".",
"Token",
",",
"nil",
"\n",
"}"
] |
// Login accepts a username and password as string arguments. Both username and
// password must be non-nil, non-empty values. Atlas does not permit
// passwordless authentication.
//
// If authentication is unsuccessful, an error is returned with the body of the
// error containing the server's response.
//
// If authentication is successful, this method sets the Token value on the
// Client and returns the Token as a string.
|
[
"Login",
"accepts",
"a",
"username",
"and",
"password",
"as",
"string",
"arguments",
".",
"Both",
"username",
"and",
"password",
"must",
"be",
"non",
"-",
"nil",
"non",
"-",
"empty",
"values",
".",
"Atlas",
"does",
"not",
"permit",
"passwordless",
"authentication",
".",
"If",
"authentication",
"is",
"unsuccessful",
"an",
"error",
"is",
"returned",
"with",
"the",
"body",
"of",
"the",
"error",
"containing",
"the",
"server",
"s",
"response",
".",
"If",
"authentication",
"is",
"successful",
"this",
"method",
"sets",
"the",
"Token",
"value",
"on",
"the",
"Client",
"and",
"returns",
"the",
"Token",
"as",
"a",
"string",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/authentication.go#L19-L63
|
20,242
|
hashicorp/atlas-go
|
v1/authentication.go
|
Verify
|
func (c *Client) Verify() error {
log.Printf("[INFO] verifying authentication")
request, err := c.Request("GET", "/api/v1/authenticate", nil)
if err != nil {
return err
}
_, err = checkResp(c.HTTPClient.Do(request))
return err
}
|
go
|
func (c *Client) Verify() error {
log.Printf("[INFO] verifying authentication")
request, err := c.Request("GET", "/api/v1/authenticate", nil)
if err != nil {
return err
}
_, err = checkResp(c.HTTPClient.Do(request))
return err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Verify",
"(",
")",
"error",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n\n",
"request",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"checkResp",
"(",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Verify verifies that authentication and communication with Atlas
// is properly functioning.
|
[
"Verify",
"verifies",
"that",
"authentication",
"and",
"communication",
"with",
"Atlas",
"is",
"properly",
"functioning",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/v1/authentication.go#L67-L77
|
20,243
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsDetect
|
func vcsDetect(path string) (*VCS, error) {
dir := path
for {
for _, v := range VCSList {
for _, f := range v.Detect {
check := filepath.Join(dir, f)
if _, err := os.Stat(check); err == nil {
return v, nil
}
}
}
lastDir := dir
dir = filepath.Dir(dir)
if dir == lastDir {
break
}
}
return nil, fmt.Errorf("no VCS found for path: %s", path)
}
|
go
|
func vcsDetect(path string) (*VCS, error) {
dir := path
for {
for _, v := range VCSList {
for _, f := range v.Detect {
check := filepath.Join(dir, f)
if _, err := os.Stat(check); err == nil {
return v, nil
}
}
}
lastDir := dir
dir = filepath.Dir(dir)
if dir == lastDir {
break
}
}
return nil, fmt.Errorf("no VCS found for path: %s", path)
}
|
[
"func",
"vcsDetect",
"(",
"path",
"string",
")",
"(",
"*",
"VCS",
",",
"error",
")",
"{",
"dir",
":=",
"path",
"\n",
"for",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"VCSList",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"v",
".",
"Detect",
"{",
"check",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"f",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"check",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"v",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"lastDir",
":=",
"dir",
"\n",
"dir",
"=",
"filepath",
".",
"Dir",
"(",
"dir",
")",
"\n",
"if",
"dir",
"==",
"lastDir",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}"
] |
// vcsDetect detects the VCS that is used for path.
|
[
"vcsDetect",
"detects",
"the",
"VCS",
"that",
"is",
"used",
"for",
"path",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L79-L98
|
20,244
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsPreflight
|
func vcsPreflight(path string) error {
vcs, err := vcsDetect(path)
if err != nil {
return fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Preflight != nil {
return vcs.Preflight(path)
}
return nil
}
|
go
|
func vcsPreflight(path string) error {
vcs, err := vcsDetect(path)
if err != nil {
return fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Preflight != nil {
return vcs.Preflight(path)
}
return nil
}
|
[
"func",
"vcsPreflight",
"(",
"path",
"string",
")",
"error",
"{",
"vcs",
",",
"err",
":=",
"vcsDetect",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"vcs",
".",
"Preflight",
"!=",
"nil",
"{",
"return",
"vcs",
".",
"Preflight",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// vcsPreflight returns the metadata for the VCS directory path.
|
[
"vcsPreflight",
"returns",
"the",
"metadata",
"for",
"the",
"VCS",
"directory",
"path",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L101-L112
|
20,245
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsFiles
|
func vcsFiles(path string) ([]string, error) {
vcs, err := vcsDetect(path)
if err != nil {
return nil, fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Files != nil {
return vcs.Files(path)
}
return nil, nil
}
|
go
|
func vcsFiles(path string) ([]string, error) {
vcs, err := vcsDetect(path)
if err != nil {
return nil, fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Files != nil {
return vcs.Files(path)
}
return nil, nil
}
|
[
"func",
"vcsFiles",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"vcs",
",",
"err",
":=",
"vcsDetect",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"vcs",
".",
"Files",
"!=",
"nil",
"{",
"return",
"vcs",
".",
"Files",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// vcsFiles returns the files for the VCS directory path.
|
[
"vcsFiles",
"returns",
"the",
"files",
"for",
"the",
"VCS",
"directory",
"path",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L115-L126
|
20,246
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsFilesCmd
|
func vcsFilesCmd(args ...string) VCSFilesFunc {
return func(path string) ([]string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf(
"error executing %s: %s",
strings.Join(args, " "),
err)
}
// Read each line of output as a path
result := make([]string, 0, 100)
scanner := bufio.NewScanner(&stdout)
for scanner.Scan() {
result = append(result, scanner.Text())
}
// Always use *nix-style paths (for Windows)
for idx, value := range result {
result[idx] = filepath.ToSlash(value)
}
return result, nil
}
}
|
go
|
func vcsFilesCmd(args ...string) VCSFilesFunc {
return func(path string) ([]string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf(
"error executing %s: %s",
strings.Join(args, " "),
err)
}
// Read each line of output as a path
result := make([]string, 0, 100)
scanner := bufio.NewScanner(&stdout)
for scanner.Scan() {
result = append(result, scanner.Text())
}
// Always use *nix-style paths (for Windows)
for idx, value := range result {
result[idx] = filepath.ToSlash(value)
}
return result, nil
}
}
|
[
"func",
"vcsFilesCmd",
"(",
"args",
"...",
"string",
")",
"VCSFilesFunc",
"{",
"return",
"func",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"stderr",
",",
"stdout",
"bytes",
".",
"Buffer",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Read each line of output as a path",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"100",
")",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"&",
"stdout",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Always use *nix-style paths (for Windows)",
"for",
"idx",
",",
"value",
":=",
"range",
"result",
"{",
"result",
"[",
"idx",
"]",
"=",
"filepath",
".",
"ToSlash",
"(",
"value",
")",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// vcsFilesCmd creates a Files-compatible function that reads the files
// by executing the command in the repository path and returning each
// line in stdout.
|
[
"vcsFilesCmd",
"creates",
"a",
"Files",
"-",
"compatible",
"function",
"that",
"reads",
"the",
"files",
"by",
"executing",
"the",
"command",
"in",
"the",
"repository",
"path",
"and",
"returning",
"each",
"line",
"in",
"stdout",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L131-L160
|
20,247
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsTrimCmd
|
func vcsTrimCmd(f VCSFilesFunc) VCSFilesFunc {
return func(path string) ([]string, error) {
absPath, err := filepath.Abs(path)
if err != nil {
return nil, fmt.Errorf(
"error expanding VCS path: %s", err)
}
// Now that we have the root path, get the inner files
fs, err := f(path)
if err != nil {
return nil, err
}
// Trim the root path from the files
result := make([]string, 0, len(fs))
for _, f := range fs {
if !strings.HasPrefix(f, absPath) {
continue
}
f, err = filepath.Rel(absPath, f)
if err != nil {
return nil, fmt.Errorf(
"error determining path: %s", err)
}
result = append(result, f)
}
return result, nil
}
}
|
go
|
func vcsTrimCmd(f VCSFilesFunc) VCSFilesFunc {
return func(path string) ([]string, error) {
absPath, err := filepath.Abs(path)
if err != nil {
return nil, fmt.Errorf(
"error expanding VCS path: %s", err)
}
// Now that we have the root path, get the inner files
fs, err := f(path)
if err != nil {
return nil, err
}
// Trim the root path from the files
result := make([]string, 0, len(fs))
for _, f := range fs {
if !strings.HasPrefix(f, absPath) {
continue
}
f, err = filepath.Rel(absPath, f)
if err != nil {
return nil, fmt.Errorf(
"error determining path: %s", err)
}
result = append(result, f)
}
return result, nil
}
}
|
[
"func",
"vcsTrimCmd",
"(",
"f",
"VCSFilesFunc",
")",
"VCSFilesFunc",
"{",
"return",
"func",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Now that we have the root path, get the inner files",
"fs",
",",
"err",
":=",
"f",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Trim the root path from the files",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"fs",
")",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"fs",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"f",
",",
"absPath",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"f",
",",
"err",
"=",
"filepath",
".",
"Rel",
"(",
"absPath",
",",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"result",
"=",
"append",
"(",
"result",
",",
"f",
")",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// vcsTrimCmd trims the prefix from the paths returned by another VCSFilesFunc.
// This should be used to wrap another function if the return value is known
// to have full paths rather than relative paths
|
[
"vcsTrimCmd",
"trims",
"the",
"prefix",
"from",
"the",
"paths",
"returned",
"by",
"another",
"VCSFilesFunc",
".",
"This",
"should",
"be",
"used",
"to",
"wrap",
"another",
"function",
"if",
"the",
"return",
"value",
"is",
"known",
"to",
"have",
"full",
"paths",
"rather",
"than",
"relative",
"paths"
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L165-L197
|
20,248
|
hashicorp/atlas-go
|
archive/vcs.go
|
vcsMetadata
|
func vcsMetadata(path string) (map[string]string, error) {
vcs, err := vcsDetect(path)
if err != nil {
return nil, fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Metadata != nil {
return vcs.Metadata(path)
}
return nil, nil
}
|
go
|
func vcsMetadata(path string) (map[string]string, error) {
vcs, err := vcsDetect(path)
if err != nil {
return nil, fmt.Errorf("error detecting VCS: %s", err)
}
if vcs.Metadata != nil {
return vcs.Metadata(path)
}
return nil, nil
}
|
[
"func",
"vcsMetadata",
"(",
"path",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"vcs",
",",
"err",
":=",
"vcsDetect",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"vcs",
".",
"Metadata",
"!=",
"nil",
"{",
"return",
"vcs",
".",
"Metadata",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// vcsMetadata returns the metadata for the VCS directory path.
|
[
"vcsMetadata",
"returns",
"the",
"metadata",
"for",
"the",
"VCS",
"directory",
"path",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L200-L211
|
20,249
|
hashicorp/atlas-go
|
archive/vcs.go
|
gitBranch
|
func gitBranch(path string) (string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
if strings.Contains(stderr.String(), ignorableDetachedHeadError) {
return "", nil
} else {
return "",
fmt.Errorf("error getting git branch: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
}
branch := strings.TrimSpace(stdout.String())
return branch, nil
}
|
go
|
func gitBranch(path string) (string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
if strings.Contains(stderr.String(), ignorableDetachedHeadError) {
return "", nil
} else {
return "",
fmt.Errorf("error getting git branch: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
}
branch := strings.TrimSpace(stdout.String())
return branch, nil
}
|
[
"func",
"gitBranch",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"stderr",
",",
"stdout",
"bytes",
".",
"Buffer",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"strings",
".",
"Contains",
"(",
"stderr",
".",
"String",
"(",
")",
",",
"ignorableDetachedHeadError",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
",",
"stdout",
".",
"String",
"(",
")",
",",
"stderr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"branch",
":=",
"strings",
".",
"TrimSpace",
"(",
"stdout",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"branch",
",",
"nil",
"\n",
"}"
] |
// gitBranch gets and returns the current git branch for the Git repository
// at the given path. It is assumed that the VCS is git.
|
[
"gitBranch",
"gets",
"and",
"returns",
"the",
"current",
"git",
"branch",
"for",
"the",
"Git",
"repository",
"at",
"the",
"given",
"path",
".",
"It",
"is",
"assumed",
"that",
"the",
"VCS",
"is",
"git",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L217-L237
|
20,250
|
hashicorp/atlas-go
|
archive/vcs.go
|
gitCommit
|
func gitCommit(path string) (string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "log", "-n1", "--pretty=format:%H")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("error getting git commit: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
commit := strings.TrimSpace(stdout.String())
return commit, nil
}
|
go
|
func gitCommit(path string) (string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "log", "-n1", "--pretty=format:%H")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("error getting git commit: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
commit := strings.TrimSpace(stdout.String())
return commit, nil
}
|
[
"func",
"gitCommit",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"stderr",
",",
"stdout",
"bytes",
".",
"Buffer",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
",",
"stdout",
".",
"String",
"(",
")",
",",
"stderr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"commit",
":=",
"strings",
".",
"TrimSpace",
"(",
"stdout",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"commit",
",",
"nil",
"\n",
"}"
] |
// gitCommit gets the SHA of the latest commit for the Git repository at the
// given path. It is assumed that the VCS is git.
|
[
"gitCommit",
"gets",
"the",
"SHA",
"of",
"the",
"latest",
"commit",
"for",
"the",
"Git",
"repository",
"at",
"the",
"given",
"path",
".",
"It",
"is",
"assumed",
"that",
"the",
"VCS",
"is",
"git",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L241-L256
|
20,251
|
hashicorp/atlas-go
|
archive/vcs.go
|
gitRemotes
|
func gitRemotes(path string) (map[string]string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "remote", "-v")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("error getting git remotes: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
// Read each line of output as a remote
result := make(map[string]string)
scanner := bufio.NewScanner(&stdout)
for scanner.Scan() {
line := scanner.Text()
split := strings.Split(line, "\t")
if len(split) < 2 {
return nil, fmt.Errorf("invalid response from git remote: %s", stdout.String())
}
remote := fmt.Sprintf("remote.%s", strings.TrimSpace(split[0]))
if _, ok := result[remote]; !ok {
// https://github.com/foo/bar.git (fetch) #=> https://github.com/foo/bar.git
urlSplit := strings.Split(split[1], " ")
result[remote] = strings.TrimSpace(urlSplit[0])
}
}
return result, nil
}
|
go
|
func gitRemotes(path string) (map[string]string, error) {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "remote", "-v")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("error getting git remotes: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
// Read each line of output as a remote
result := make(map[string]string)
scanner := bufio.NewScanner(&stdout)
for scanner.Scan() {
line := scanner.Text()
split := strings.Split(line, "\t")
if len(split) < 2 {
return nil, fmt.Errorf("invalid response from git remote: %s", stdout.String())
}
remote := fmt.Sprintf("remote.%s", strings.TrimSpace(split[0]))
if _, ok := result[remote]; !ok {
// https://github.com/foo/bar.git (fetch) #=> https://github.com/foo/bar.git
urlSplit := strings.Split(split[1], " ")
result[remote] = strings.TrimSpace(urlSplit[0])
}
}
return result, nil
}
|
[
"func",
"gitRemotes",
"(",
"path",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"stderr",
",",
"stdout",
"bytes",
".",
"Buffer",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
",",
"stdout",
".",
"String",
"(",
")",
",",
"stderr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Read each line of output as a remote",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"&",
"stdout",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"line",
":=",
"scanner",
".",
"Text",
"(",
")",
"\n",
"split",
":=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\\t",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"split",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"stdout",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"remote",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"TrimSpace",
"(",
"split",
"[",
"0",
"]",
")",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"result",
"[",
"remote",
"]",
";",
"!",
"ok",
"{",
"// https://github.com/foo/bar.git (fetch) #=> https://github.com/foo/bar.git",
"urlSplit",
":=",
"strings",
".",
"Split",
"(",
"split",
"[",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"result",
"[",
"remote",
"]",
"=",
"strings",
".",
"TrimSpace",
"(",
"urlSplit",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// gitRemotes gets and returns a map of all remotes for the Git repository. The
// map key is the name of the remote of the format "remote.NAME" and the value
// is the endpoint for the remote. It is assumed that the VCS is git.
|
[
"gitRemotes",
"gets",
"and",
"returns",
"a",
"map",
"of",
"all",
"remotes",
"for",
"the",
"Git",
"repository",
".",
"The",
"map",
"key",
"is",
"the",
"name",
"of",
"the",
"remote",
"of",
"the",
"format",
"remote",
".",
"NAME",
"and",
"the",
"value",
"is",
"the",
"endpoint",
"for",
"the",
"remote",
".",
"It",
"is",
"assumed",
"that",
"the",
"VCS",
"is",
"git",
"."
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L261-L293
|
20,252
|
hashicorp/atlas-go
|
archive/vcs.go
|
gitPreflight
|
func gitPreflight(path string) error {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "--version")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error getting git version: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
// Check if the output is valid
output := strings.Split(strings.TrimSpace(stdout.String()), " ")
if len(output) < 1 {
log.Printf("[WARN] could not extract version output from Git")
return nil
}
// Parse the version
gitv, err := version.NewVersion(output[len(output)-1])
if err != nil {
log.Printf("[WARN] could not parse version output from Git")
return nil
}
constraint, err := version.NewConstraint("> 1.8")
if err != nil {
log.Printf("[WARN] could not create version constraint to check")
return nil
}
if !constraint.Check(gitv) {
return fmt.Errorf("git version (%s) is too old, please upgrade", gitv.String())
}
return nil
}
|
go
|
func gitPreflight(path string) error {
var stderr, stdout bytes.Buffer
cmd := exec.Command("git", "--version")
cmd.Dir = path
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error getting git version: %s\nstdout: %s\nstderr: %s",
err, stdout.String(), stderr.String())
}
// Check if the output is valid
output := strings.Split(strings.TrimSpace(stdout.String()), " ")
if len(output) < 1 {
log.Printf("[WARN] could not extract version output from Git")
return nil
}
// Parse the version
gitv, err := version.NewVersion(output[len(output)-1])
if err != nil {
log.Printf("[WARN] could not parse version output from Git")
return nil
}
constraint, err := version.NewConstraint("> 1.8")
if err != nil {
log.Printf("[WARN] could not create version constraint to check")
return nil
}
if !constraint.Check(gitv) {
return fmt.Errorf("git version (%s) is too old, please upgrade", gitv.String())
}
return nil
}
|
[
"func",
"gitPreflight",
"(",
"path",
"string",
")",
"error",
"{",
"var",
"stderr",
",",
"stdout",
"bytes",
".",
"Buffer",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
",",
"stdout",
".",
"String",
"(",
")",
",",
"stderr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Check if the output is valid",
"output",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"stdout",
".",
"String",
"(",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"output",
")",
"<",
"1",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Parse the version",
"gitv",
",",
"err",
":=",
"version",
".",
"NewVersion",
"(",
"output",
"[",
"len",
"(",
"output",
")",
"-",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"constraint",
",",
"err",
":=",
"version",
".",
"NewConstraint",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"constraint",
".",
"Check",
"(",
"gitv",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gitv",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// gitPreflight is the pre-flight command that runs for Git-based VCSs
|
[
"gitPreflight",
"is",
"the",
"pre",
"-",
"flight",
"command",
"that",
"runs",
"for",
"Git",
"-",
"based",
"VCSs"
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L296-L332
|
20,253
|
hashicorp/atlas-go
|
archive/vcs.go
|
gitMetadata
|
func gitMetadata(path string) (map[string]string, error) {
// Future-self note: Git is NOT threadsafe, so we cannot run these
// operations in go routines or else you're going to have a really really
// bad day and Panda.State == "Sad" :(
branch, err := gitBranch(path)
if err != nil {
return nil, err
}
commit, err := gitCommit(path)
if err != nil {
return nil, err
}
remotes, err := gitRemotes(path)
if err != nil {
return nil, err
}
// Make the return result (we already know the size)
result := make(map[string]string, 2+len(remotes))
result["branch"] = branch
result["commit"] = commit
for remote, value := range remotes {
result[remote] = value
}
return result, nil
}
|
go
|
func gitMetadata(path string) (map[string]string, error) {
// Future-self note: Git is NOT threadsafe, so we cannot run these
// operations in go routines or else you're going to have a really really
// bad day and Panda.State == "Sad" :(
branch, err := gitBranch(path)
if err != nil {
return nil, err
}
commit, err := gitCommit(path)
if err != nil {
return nil, err
}
remotes, err := gitRemotes(path)
if err != nil {
return nil, err
}
// Make the return result (we already know the size)
result := make(map[string]string, 2+len(remotes))
result["branch"] = branch
result["commit"] = commit
for remote, value := range remotes {
result[remote] = value
}
return result, nil
}
|
[
"func",
"gitMetadata",
"(",
"path",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"// Future-self note: Git is NOT threadsafe, so we cannot run these",
"// operations in go routines or else you're going to have a really really",
"// bad day and Panda.State == \"Sad\" :(",
"branch",
",",
"err",
":=",
"gitBranch",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"commit",
",",
"err",
":=",
"gitCommit",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"remotes",
",",
"err",
":=",
"gitRemotes",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Make the return result (we already know the size)",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"2",
"+",
"len",
"(",
"remotes",
")",
")",
"\n\n",
"result",
"[",
"\"",
"\"",
"]",
"=",
"branch",
"\n",
"result",
"[",
"\"",
"\"",
"]",
"=",
"commit",
"\n",
"for",
"remote",
",",
"value",
":=",
"range",
"remotes",
"{",
"result",
"[",
"remote",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// gitMetadata is the function to parse and return Git metadata
|
[
"gitMetadata",
"is",
"the",
"function",
"to",
"parse",
"and",
"return",
"Git",
"metadata"
] |
8261ea0801056858f57a58ee6ce37b9365a78ce9
|
https://github.com/hashicorp/atlas-go/blob/8261ea0801056858f57a58ee6ce37b9365a78ce9/archive/vcs.go#L335-L365
|
20,254
|
gojuno/minimock
|
mock_controller.go
|
RegisterMocker
|
func (c *Controller) RegisterMocker(m Mocker) {
c.Lock()
c.mockers = append(c.mockers, m)
c.Unlock()
}
|
go
|
func (c *Controller) RegisterMocker(m Mocker) {
c.Lock()
c.mockers = append(c.mockers, m)
c.Unlock()
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"RegisterMocker",
"(",
"m",
"Mocker",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"mockers",
"=",
"append",
"(",
"c",
".",
"mockers",
",",
"m",
")",
"\n",
"c",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
//RegisterMocker puts mocker to the list of controller mockers
|
[
"RegisterMocker",
"puts",
"mocker",
"to",
"the",
"list",
"of",
"controller",
"mockers"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/mock_controller.go#L50-L54
|
20,255
|
gojuno/minimock
|
mock_controller.go
|
Finish
|
func (c *Controller) Finish() {
c.Lock()
for _, m := range c.mockers {
m.MinimockFinish()
}
c.Unlock()
}
|
go
|
func (c *Controller) Finish() {
c.Lock()
for _, m := range c.mockers {
m.MinimockFinish()
}
c.Unlock()
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Finish",
"(",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"c",
".",
"mockers",
"{",
"m",
".",
"MinimockFinish",
"(",
")",
"\n",
"}",
"\n",
"c",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
//Finish calls to MinimockFinish method for all registered mockers
|
[
"Finish",
"calls",
"to",
"MinimockFinish",
"method",
"for",
"all",
"registered",
"mockers"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/mock_controller.go#L57-L63
|
20,256
|
gojuno/minimock
|
mock_controller.go
|
Wait
|
func (c *Controller) Wait(d time.Duration) {
wg := sync.WaitGroup{}
wg.Add(len(c.mockers))
for _, m := range c.mockers {
go func(m Mocker) {
defer wg.Done()
m.MinimockWait(d)
}(m)
}
wg.Wait()
}
|
go
|
func (c *Controller) Wait(d time.Duration) {
wg := sync.WaitGroup{}
wg.Add(len(c.mockers))
for _, m := range c.mockers {
go func(m Mocker) {
defer wg.Done()
m.MinimockWait(d)
}(m)
}
wg.Wait()
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Wait",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"c",
".",
"mockers",
")",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"c",
".",
"mockers",
"{",
"go",
"func",
"(",
"m",
"Mocker",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"m",
".",
"MinimockWait",
"(",
"d",
")",
"\n",
"}",
"(",
"m",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}"
] |
//Wait calls to MinimockWait method for all registered mockers
|
[
"Wait",
"calls",
"to",
"MinimockWait",
"method",
"for",
"all",
"registered",
"mockers"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/mock_controller.go#L66-L77
|
20,257
|
gojuno/minimock
|
camel_to_snake.go
|
CamelToSnake
|
func CamelToSnake(s string) string {
b := buffer{
r: make([]byte, 0, len(s)),
}
var m rune
var w bool
for _, ch := range s {
if unicode.IsUpper(ch) {
if m != 0 {
if !w {
b.indent()
w = true
}
b.write(m)
}
m = unicode.ToLower(ch)
} else {
if m != 0 {
b.indent()
b.write(m)
m = 0
w = false
}
b.write(ch)
}
}
if m != 0 {
if !w {
b.indent()
}
b.write(m)
}
return string(b.r)
}
|
go
|
func CamelToSnake(s string) string {
b := buffer{
r: make([]byte, 0, len(s)),
}
var m rune
var w bool
for _, ch := range s {
if unicode.IsUpper(ch) {
if m != 0 {
if !w {
b.indent()
w = true
}
b.write(m)
}
m = unicode.ToLower(ch)
} else {
if m != 0 {
b.indent()
b.write(m)
m = 0
w = false
}
b.write(ch)
}
}
if m != 0 {
if !w {
b.indent()
}
b.write(m)
}
return string(b.r)
}
|
[
"func",
"CamelToSnake",
"(",
"s",
"string",
")",
"string",
"{",
"b",
":=",
"buffer",
"{",
"r",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"s",
")",
")",
",",
"}",
"\n",
"var",
"m",
"rune",
"\n",
"var",
"w",
"bool",
"\n",
"for",
"_",
",",
"ch",
":=",
"range",
"s",
"{",
"if",
"unicode",
".",
"IsUpper",
"(",
"ch",
")",
"{",
"if",
"m",
"!=",
"0",
"{",
"if",
"!",
"w",
"{",
"b",
".",
"indent",
"(",
")",
"\n",
"w",
"=",
"true",
"\n",
"}",
"\n",
"b",
".",
"write",
"(",
"m",
")",
"\n",
"}",
"\n",
"m",
"=",
"unicode",
".",
"ToLower",
"(",
"ch",
")",
"\n",
"}",
"else",
"{",
"if",
"m",
"!=",
"0",
"{",
"b",
".",
"indent",
"(",
")",
"\n",
"b",
".",
"write",
"(",
"m",
")",
"\n",
"m",
"=",
"0",
"\n",
"w",
"=",
"false",
"\n",
"}",
"\n",
"b",
".",
"write",
"(",
"ch",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"m",
"!=",
"0",
"{",
"if",
"!",
"w",
"{",
"b",
".",
"indent",
"(",
")",
"\n",
"}",
"\n",
"b",
".",
"write",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
".",
"r",
")",
"\n",
"}"
] |
// CamelToSnake transforms strings from CamelCase to snake_case
|
[
"CamelToSnake",
"transforms",
"strings",
"from",
"CamelCase",
"to",
"snake_case"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/camel_to_snake.go#L29-L62
|
20,258
|
gojuno/minimock
|
cmd/minimock/minimock.go
|
checkDuplicateOutputFiles
|
func checkDuplicateOutputFiles(fileNames []string) error {
for i := range fileNames {
ok, err := isGoFile(fileNames[i])
if err != nil {
return err
}
if !ok {
continue
}
ipath, err := filepath.Abs(fileNames[i])
if err != nil {
return err
}
for j := range fileNames {
jpath, err := filepath.Abs(fileNames[j])
if err != nil {
return err
}
if j != i && ipath == jpath {
return errors.Errorf("duplicate output file name: %s", ipath)
}
}
}
return nil
}
|
go
|
func checkDuplicateOutputFiles(fileNames []string) error {
for i := range fileNames {
ok, err := isGoFile(fileNames[i])
if err != nil {
return err
}
if !ok {
continue
}
ipath, err := filepath.Abs(fileNames[i])
if err != nil {
return err
}
for j := range fileNames {
jpath, err := filepath.Abs(fileNames[j])
if err != nil {
return err
}
if j != i && ipath == jpath {
return errors.Errorf("duplicate output file name: %s", ipath)
}
}
}
return nil
}
|
[
"func",
"checkDuplicateOutputFiles",
"(",
"fileNames",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"fileNames",
"{",
"ok",
",",
"err",
":=",
"isGoFile",
"(",
"fileNames",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"ipath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"fileNames",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"j",
":=",
"range",
"fileNames",
"{",
"jpath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"fileNames",
"[",
"j",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"j",
"!=",
"i",
"&&",
"ipath",
"==",
"jpath",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipath",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// checkDuplicateOutputFiles finds first non-unique Go file
|
[
"checkDuplicateOutputFiles",
"finds",
"first",
"non",
"-",
"unique",
"Go",
"file"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/cmd/minimock/minimock.go#L309-L338
|
20,259
|
gojuno/minimock
|
equal.go
|
Equal
|
func Equal(a, b interface{}) bool {
if a == nil && b == nil {
return a == b
}
return reflect.DeepEqual(a, b)
}
|
go
|
func Equal(a, b interface{}) bool {
if a == nil && b == nil {
return a == b
}
return reflect.DeepEqual(a, b)
}
|
[
"func",
"Equal",
"(",
"a",
",",
"b",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"a",
"==",
"nil",
"&&",
"b",
"==",
"nil",
"{",
"return",
"a",
"==",
"b",
"\n",
"}",
"\n\n",
"return",
"reflect",
".",
"DeepEqual",
"(",
"a",
",",
"b",
")",
"\n",
"}"
] |
// Equal returns true if a equals b
|
[
"Equal",
"returns",
"true",
"if",
"a",
"equals",
"b"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/equal.go#L17-L23
|
20,260
|
gojuno/minimock
|
equal.go
|
Diff
|
func Diff(e, a interface{}) string {
if e == nil || a == nil {
return ""
}
t := reflect.TypeOf(e)
k := t.Kind()
if reflect.TypeOf(a) != t {
return ""
}
if k == reflect.Ptr {
t = t.Elem()
k = t.Kind()
}
if k != reflect.Array && k != reflect.Map && k != reflect.Slice && k != reflect.Struct {
return ""
}
es := dumpConf.Sdump(e)
as := dumpConf.Sdump(a)
diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(es),
B: difflib.SplitLines(as),
Context: 1,
FromFile: "Expected params",
ToFile: "Actual params",
})
if err != nil {
panic(err)
}
return "\n\nDiff:\n" + diff
}
|
go
|
func Diff(e, a interface{}) string {
if e == nil || a == nil {
return ""
}
t := reflect.TypeOf(e)
k := t.Kind()
if reflect.TypeOf(a) != t {
return ""
}
if k == reflect.Ptr {
t = t.Elem()
k = t.Kind()
}
if k != reflect.Array && k != reflect.Map && k != reflect.Slice && k != reflect.Struct {
return ""
}
es := dumpConf.Sdump(e)
as := dumpConf.Sdump(a)
diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(es),
B: difflib.SplitLines(as),
Context: 1,
FromFile: "Expected params",
ToFile: "Actual params",
})
if err != nil {
panic(err)
}
return "\n\nDiff:\n" + diff
}
|
[
"func",
"Diff",
"(",
"e",
",",
"a",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"e",
"==",
"nil",
"||",
"a",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"e",
")",
"\n",
"k",
":=",
"t",
".",
"Kind",
"(",
")",
"\n\n",
"if",
"reflect",
".",
"TypeOf",
"(",
"a",
")",
"!=",
"t",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"k",
"==",
"reflect",
".",
"Ptr",
"{",
"t",
"=",
"t",
".",
"Elem",
"(",
")",
"\n",
"k",
"=",
"t",
".",
"Kind",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"k",
"!=",
"reflect",
".",
"Array",
"&&",
"k",
"!=",
"reflect",
".",
"Map",
"&&",
"k",
"!=",
"reflect",
".",
"Slice",
"&&",
"k",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"es",
":=",
"dumpConf",
".",
"Sdump",
"(",
"e",
")",
"\n",
"as",
":=",
"dumpConf",
".",
"Sdump",
"(",
"a",
")",
"\n\n",
"diff",
",",
"err",
":=",
"difflib",
".",
"GetUnifiedDiffString",
"(",
"difflib",
".",
"UnifiedDiff",
"{",
"A",
":",
"difflib",
".",
"SplitLines",
"(",
"es",
")",
",",
"B",
":",
"difflib",
".",
"SplitLines",
"(",
"as",
")",
",",
"Context",
":",
"1",
",",
"FromFile",
":",
"\"",
"\"",
",",
"ToFile",
":",
"\"",
"\"",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
"+",
"diff",
"\n",
"}"
] |
// Diff returns unified diff of the textual representations of e and a
|
[
"Diff",
"returns",
"unified",
"diff",
"of",
"the",
"textual",
"representations",
"of",
"e",
"and",
"a"
] |
31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e
|
https://github.com/gojuno/minimock/blob/31e8b94eb68b6c2a9e6eca57dd63a0f2392bbf1e/equal.go#L26-L63
|
20,261
|
p4tin/goaws
|
app/router/router.go
|
New
|
func New() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/", actionHandler).Methods("GET", "POST")
r.HandleFunc("/{account}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/queue/{queueName}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/{account}/{queueName}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/SimpleNotificationService/{id}.pem", pemHandler).Methods("GET")
r.HandleFunc("/health", health).Methods("GET")
return r
}
|
go
|
func New() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/", actionHandler).Methods("GET", "POST")
r.HandleFunc("/{account}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/queue/{queueName}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/{account}/{queueName}", actionHandler).Methods("GET", "POST")
r.HandleFunc("/SimpleNotificationService/{id}.pem", pemHandler).Methods("GET")
r.HandleFunc("/health", health).Methods("GET")
return r
}
|
[
"func",
"New",
"(",
")",
"http",
".",
"Handler",
"{",
"r",
":=",
"mux",
".",
"NewRouter",
"(",
")",
"\n\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"actionHandler",
")",
".",
"Methods",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"actionHandler",
")",
".",
"Methods",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"actionHandler",
")",
".",
"Methods",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"actionHandler",
")",
".",
"Methods",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"pemHandler",
")",
".",
"Methods",
"(",
"\"",
"\"",
")",
"\n",
"r",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"health",
")",
".",
"Methods",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"r",
"\n",
"}"
] |
// New returns a new router
|
[
"New",
"returns",
"a",
"new",
"router"
] |
8d635c3b676f0c0c92ed0c86f70ee7256a877ac7
|
https://github.com/p4tin/goaws/blob/8d635c3b676f0c0c92ed0c86f70ee7256a877ac7/app/router/router.go#L17-L28
|
20,262
|
p4tin/goaws
|
app/sns.go
|
IsSatisfiedBy
|
func (fp *FilterPolicy) IsSatisfiedBy(msgAttrs map[string]MessageAttributeValue) bool {
for policyAttrName, policyAttrValues := range *fp {
attrValue, ok := msgAttrs[policyAttrName]
if !ok {
return false // the attribute has to be present in the message
}
// String, String.Array, Number data-types are allowed by SNS filter policies
// however go-AWS currently only supports String filter policies. That feature can be added here
// ref: https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html
if attrValue.DataType != "String" {
return false
}
if !stringInSlice(attrValue.Value, policyAttrValues) {
return false // the attribute value has to be among filtered ones
}
}
return true
}
|
go
|
func (fp *FilterPolicy) IsSatisfiedBy(msgAttrs map[string]MessageAttributeValue) bool {
for policyAttrName, policyAttrValues := range *fp {
attrValue, ok := msgAttrs[policyAttrName]
if !ok {
return false // the attribute has to be present in the message
}
// String, String.Array, Number data-types are allowed by SNS filter policies
// however go-AWS currently only supports String filter policies. That feature can be added here
// ref: https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html
if attrValue.DataType != "String" {
return false
}
if !stringInSlice(attrValue.Value, policyAttrValues) {
return false // the attribute value has to be among filtered ones
}
}
return true
}
|
[
"func",
"(",
"fp",
"*",
"FilterPolicy",
")",
"IsSatisfiedBy",
"(",
"msgAttrs",
"map",
"[",
"string",
"]",
"MessageAttributeValue",
")",
"bool",
"{",
"for",
"policyAttrName",
",",
"policyAttrValues",
":=",
"range",
"*",
"fp",
"{",
"attrValue",
",",
"ok",
":=",
"msgAttrs",
"[",
"policyAttrName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"// the attribute has to be present in the message",
"\n",
"}",
"\n\n",
"// String, String.Array, Number data-types are allowed by SNS filter policies",
"// however go-AWS currently only supports String filter policies. That feature can be added here",
"// ref: https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html",
"if",
"attrValue",
".",
"DataType",
"!=",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"!",
"stringInSlice",
"(",
"attrValue",
".",
"Value",
",",
"policyAttrValues",
")",
"{",
"return",
"false",
"// the attribute value has to be among filtered ones",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// Function checks if MessageAttributes passed to Topic satisfy FilterPolicy set by subscription
|
[
"Function",
"checks",
"if",
"MessageAttributes",
"passed",
"to",
"Topic",
"satisfy",
"FilterPolicy",
"set",
"by",
"subscription"
] |
8d635c3b676f0c0c92ed0c86f70ee7256a877ac7
|
https://github.com/p4tin/goaws/blob/8d635c3b676f0c0c92ed0c86f70ee7256a877ac7/app/sns.go#L49-L69
|
20,263
|
InVisionApp/go-health
|
examples/status-listener/dependency/dependency.go
|
shouldBreakThings
|
func (l *loki) shouldBreakThings() bool {
l.Lock()
defer l.Unlock()
l.callcount++
if l.callcount > 15 {
l.callcount = 0
return false
}
if l.callcount > 10 {
return true
}
return false
}
|
go
|
func (l *loki) shouldBreakThings() bool {
l.Lock()
defer l.Unlock()
l.callcount++
if l.callcount > 15 {
l.callcount = 0
return false
}
if l.callcount > 10 {
return true
}
return false
}
|
[
"func",
"(",
"l",
"*",
"loki",
")",
"shouldBreakThings",
"(",
")",
"bool",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"l",
".",
"callcount",
"++",
"\n",
"if",
"l",
".",
"callcount",
">",
"15",
"{",
"l",
".",
"callcount",
"=",
"0",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"if",
"l",
".",
"callcount",
">",
"10",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// this is just a function that will return true
// the last 5 out of every 15 times called
|
[
"this",
"is",
"just",
"a",
"function",
"that",
"will",
"return",
"true",
"the",
"last",
"5",
"out",
"of",
"every",
"15",
"times",
"called"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/examples/status-listener/dependency/dependency.go#L18-L31
|
20,264
|
InVisionApp/go-health
|
examples/custom-checker-server/custom-checker-server.go
|
Status
|
func (c *customCheck) Status() (interface{}, error) {
// perform some sort of check
if false {
return nil, fmt.Errorf("Something major just broke")
}
// You can return additional information pertaining to the check as long
// as it can be JSON marshalled
return map[string]int{"foo": 123, "bar": 456}, nil
}
|
go
|
func (c *customCheck) Status() (interface{}, error) {
// perform some sort of check
if false {
return nil, fmt.Errorf("Something major just broke")
}
// You can return additional information pertaining to the check as long
// as it can be JSON marshalled
return map[string]int{"foo": 123, "bar": 456}, nil
}
|
[
"func",
"(",
"c",
"*",
"customCheck",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// perform some sort of check",
"if",
"false",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// You can return additional information pertaining to the check as long",
"// as it can be JSON marshalled",
"return",
"map",
"[",
"string",
"]",
"int",
"{",
"\"",
"\"",
":",
"123",
",",
"\"",
"\"",
":",
"456",
"}",
",",
"nil",
"\n",
"}"
] |
// Satisfy the go-health.ICheckable interface
|
[
"Satisfy",
"the",
"go",
"-",
"health",
".",
"ICheckable",
"interface"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/examples/custom-checker-server/custom-checker-server.go#L45-L54
|
20,265
|
InVisionApp/go-health
|
checkers/disk/disk_usage.go
|
Status
|
func (d *DiskUsage) Status() (interface{}, error) {
stats, err := disk.Usage(d.Config.Path)
if err != nil {
return nil, fmt.Errorf("Error getting disk usage: %v", err)
}
diskUsage := stats.UsedPercent
if diskUsage >= d.Config.CriticalThreshold {
return nil, fmt.Errorf("Critical: disk usage too high %.2f percent", diskUsage)
}
if diskUsage >= d.Config.WarningThreshold {
return nil, fmt.Errorf("Warning: disk usage too high %.2f percent", diskUsage)
}
return nil, nil
}
|
go
|
func (d *DiskUsage) Status() (interface{}, error) {
stats, err := disk.Usage(d.Config.Path)
if err != nil {
return nil, fmt.Errorf("Error getting disk usage: %v", err)
}
diskUsage := stats.UsedPercent
if diskUsage >= d.Config.CriticalThreshold {
return nil, fmt.Errorf("Critical: disk usage too high %.2f percent", diskUsage)
}
if diskUsage >= d.Config.WarningThreshold {
return nil, fmt.Errorf("Warning: disk usage too high %.2f percent", diskUsage)
}
return nil, nil
}
|
[
"func",
"(",
"d",
"*",
"DiskUsage",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"stats",
",",
"err",
":=",
"disk",
".",
"Usage",
"(",
"d",
".",
"Config",
".",
"Path",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"diskUsage",
":=",
"stats",
".",
"UsedPercent",
"\n\n",
"if",
"diskUsage",
">=",
"d",
".",
"Config",
".",
"CriticalThreshold",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"diskUsage",
")",
"\n",
"}",
"\n\n",
"if",
"diskUsage",
">=",
"d",
".",
"Config",
".",
"WarningThreshold",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"diskUsage",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// Status is used for performing a diskusage check against a dependency; it satisfies
// the "ICheckable" interface.
|
[
"Status",
"is",
"used",
"for",
"performing",
"a",
"diskusage",
"check",
"against",
"a",
"dependency",
";",
"it",
"satisfies",
"the",
"ICheckable",
"interface",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/disk/disk_usage.go#L43-L61
|
20,266
|
InVisionApp/go-health
|
health.go
|
New
|
func New() *Health {
return &Health{
Logger: log.NewSimple(),
configs: make([]*Config, 0),
states: make(map[string]State, 0),
runners: make(map[string]chan struct{}, 0),
active: newBool(),
statesLock: sync.Mutex{},
}
}
|
go
|
func New() *Health {
return &Health{
Logger: log.NewSimple(),
configs: make([]*Config, 0),
states: make(map[string]State, 0),
runners: make(map[string]chan struct{}, 0),
active: newBool(),
statesLock: sync.Mutex{},
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Health",
"{",
"return",
"&",
"Health",
"{",
"Logger",
":",
"log",
".",
"NewSimple",
"(",
")",
",",
"configs",
":",
"make",
"(",
"[",
"]",
"*",
"Config",
",",
"0",
")",
",",
"states",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"State",
",",
"0",
")",
",",
"runners",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"chan",
"struct",
"{",
"}",
",",
"0",
")",
",",
"active",
":",
"newBool",
"(",
")",
",",
"statesLock",
":",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// New returns a new instance of the Health struct.
|
[
"New",
"returns",
"a",
"new",
"instance",
"of",
"the",
"Health",
"struct",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L137-L146
|
20,267
|
InVisionApp/go-health
|
health.go
|
AddCheck
|
func (h *Health) AddCheck(cfg *Config) error {
if h.active.val() {
return ErrNoAddCfgWhenActive
}
h.configs = append(h.configs, cfg)
return nil
}
|
go
|
func (h *Health) AddCheck(cfg *Config) error {
if h.active.val() {
return ErrNoAddCfgWhenActive
}
h.configs = append(h.configs, cfg)
return nil
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"AddCheck",
"(",
"cfg",
"*",
"Config",
")",
"error",
"{",
"if",
"h",
".",
"active",
".",
"val",
"(",
")",
"{",
"return",
"ErrNoAddCfgWhenActive",
"\n",
"}",
"\n\n",
"h",
".",
"configs",
"=",
"append",
"(",
"h",
".",
"configs",
",",
"cfg",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddCheck is used for adding a single check definition to the current health
// instance.
|
[
"AddCheck",
"is",
"used",
"for",
"adding",
"a",
"single",
"check",
"definition",
"to",
"the",
"current",
"health",
"instance",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L167-L174
|
20,268
|
InVisionApp/go-health
|
health.go
|
Stop
|
func (h *Health) Stop() error {
if !h.active.val() {
return ErrAlreadyStopped
}
for name, stop := range h.runners {
h.Logger.WithFields(log.Fields{"name": name}).Debug("Stopping checker")
close(stop)
}
// Reset runner map
h.runners = make(map[string]chan struct{}, 0)
// Reset states
h.safeResetStates()
return nil
}
|
go
|
func (h *Health) Stop() error {
if !h.active.val() {
return ErrAlreadyStopped
}
for name, stop := range h.runners {
h.Logger.WithFields(log.Fields{"name": name}).Debug("Stopping checker")
close(stop)
}
// Reset runner map
h.runners = make(map[string]chan struct{}, 0)
// Reset states
h.safeResetStates()
return nil
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"Stop",
"(",
")",
"error",
"{",
"if",
"!",
"h",
".",
"active",
".",
"val",
"(",
")",
"{",
"return",
"ErrAlreadyStopped",
"\n",
"}",
"\n\n",
"for",
"name",
",",
"stop",
":=",
"range",
"h",
".",
"runners",
"{",
"h",
".",
"Logger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"name",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"close",
"(",
"stop",
")",
"\n",
"}",
"\n\n",
"// Reset runner map",
"h",
".",
"runners",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"chan",
"struct",
"{",
"}",
",",
"0",
")",
"\n\n",
"// Reset states",
"h",
".",
"safeResetStates",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Stop will cause all of the running health checks to be stopped. Additionally,
// all existing check states will be reset.
|
[
"Stop",
"will",
"cause",
"all",
"of",
"the",
"running",
"health",
"checks",
"to",
"be",
"stopped",
".",
"Additionally",
"all",
"existing",
"check",
"states",
"will",
"be",
"reset",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L206-L223
|
20,269
|
InVisionApp/go-health
|
health.go
|
Failed
|
func (h *Health) Failed() bool {
for _, val := range h.safeGetStates() {
if val.Fatal && val.isFailure() {
return true
}
}
return false
}
|
go
|
func (h *Health) Failed() bool {
for _, val := range h.safeGetStates() {
if val.Fatal && val.isFailure() {
return true
}
}
return false
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"Failed",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"h",
".",
"safeGetStates",
"(",
")",
"{",
"if",
"val",
".",
"Fatal",
"&&",
"val",
".",
"isFailure",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// Failed will return the basic state of overall health. This should be used when
// details about the failure are not needed
|
[
"Failed",
"will",
"return",
"the",
"basic",
"state",
"of",
"overall",
"health",
".",
"This",
"should",
"be",
"used",
"when",
"details",
"about",
"the",
"failure",
"are",
"not",
"needed"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L239-L246
|
20,270
|
InVisionApp/go-health
|
health.go
|
safeResetStates
|
func (h *Health) safeResetStates() {
h.statesLock.Lock()
defer h.statesLock.Unlock()
h.states = make(map[string]State, 0)
}
|
go
|
func (h *Health) safeResetStates() {
h.statesLock.Lock()
defer h.statesLock.Unlock()
h.states = make(map[string]State, 0)
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"safeResetStates",
"(",
")",
"{",
"h",
".",
"statesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"statesLock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"states",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"State",
",",
"0",
")",
"\n",
"}"
] |
// resets the states in a concurrency-safe manner
|
[
"resets",
"the",
"states",
"in",
"a",
"concurrency",
"-",
"safe",
"manner"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L302-L306
|
20,271
|
InVisionApp/go-health
|
health.go
|
safeUpdateState
|
func (h *Health) safeUpdateState(stateEntry *State) {
// dispatch any status listeners
h.handleStatusListener(stateEntry)
// update states here
h.statesLock.Lock()
defer h.statesLock.Unlock()
h.states[stateEntry.Name] = *stateEntry
}
|
go
|
func (h *Health) safeUpdateState(stateEntry *State) {
// dispatch any status listeners
h.handleStatusListener(stateEntry)
// update states here
h.statesLock.Lock()
defer h.statesLock.Unlock()
h.states[stateEntry.Name] = *stateEntry
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"safeUpdateState",
"(",
"stateEntry",
"*",
"State",
")",
"{",
"// dispatch any status listeners",
"h",
".",
"handleStatusListener",
"(",
"stateEntry",
")",
"\n\n",
"// update states here",
"h",
".",
"statesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"statesLock",
".",
"Unlock",
"(",
")",
"\n\n",
"h",
".",
"states",
"[",
"stateEntry",
".",
"Name",
"]",
"=",
"*",
"stateEntry",
"\n",
"}"
] |
// updates the check state in a concurrency-safe manner
|
[
"updates",
"the",
"check",
"state",
"in",
"a",
"concurrency",
"-",
"safe",
"manner"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L309-L318
|
20,272
|
InVisionApp/go-health
|
health.go
|
safeGetStates
|
func (h *Health) safeGetStates() map[string]State {
h.statesLock.Lock()
defer h.statesLock.Unlock()
// deep copy h.states to avoid race
statesCopy := make(map[string]State, 0)
for k, v := range h.states {
statesCopy[k] = v
}
return statesCopy
}
|
go
|
func (h *Health) safeGetStates() map[string]State {
h.statesLock.Lock()
defer h.statesLock.Unlock()
// deep copy h.states to avoid race
statesCopy := make(map[string]State, 0)
for k, v := range h.states {
statesCopy[k] = v
}
return statesCopy
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"safeGetStates",
"(",
")",
"map",
"[",
"string",
"]",
"State",
"{",
"h",
".",
"statesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"statesLock",
".",
"Unlock",
"(",
")",
"\n\n",
"// deep copy h.states to avoid race",
"statesCopy",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"State",
",",
"0",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"h",
".",
"states",
"{",
"statesCopy",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"statesCopy",
"\n",
"}"
] |
// get all states in a concurrency-safe manner
|
[
"get",
"all",
"states",
"in",
"a",
"concurrency",
"-",
"safe",
"manner"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L321-L333
|
20,273
|
InVisionApp/go-health
|
health.go
|
handleStatusListener
|
func (h *Health) handleStatusListener(stateEntry *State) {
// get the previous state
h.statesLock.Lock()
prevState := h.states[stateEntry.Name]
h.statesLock.Unlock()
// state is failure
if stateEntry.isFailure() {
if !prevState.isFailure() {
// new failure: previous state was ok
if h.StatusListener != nil {
go h.StatusListener.HealthCheckFailed(stateEntry)
}
stateEntry.TimeOfFirstFailure = time.Now()
} else {
// carry the time of first failure from the previous state
stateEntry.TimeOfFirstFailure = prevState.TimeOfFirstFailure
}
stateEntry.ContiguousFailures = prevState.ContiguousFailures + 1
} else if prevState.isFailure() {
// recovery, previous state was failure
failureSeconds := time.Now().Sub(prevState.TimeOfFirstFailure).Seconds()
if h.StatusListener != nil {
go h.StatusListener.HealthCheckRecovered(stateEntry, prevState.ContiguousFailures, failureSeconds)
}
}
}
|
go
|
func (h *Health) handleStatusListener(stateEntry *State) {
// get the previous state
h.statesLock.Lock()
prevState := h.states[stateEntry.Name]
h.statesLock.Unlock()
// state is failure
if stateEntry.isFailure() {
if !prevState.isFailure() {
// new failure: previous state was ok
if h.StatusListener != nil {
go h.StatusListener.HealthCheckFailed(stateEntry)
}
stateEntry.TimeOfFirstFailure = time.Now()
} else {
// carry the time of first failure from the previous state
stateEntry.TimeOfFirstFailure = prevState.TimeOfFirstFailure
}
stateEntry.ContiguousFailures = prevState.ContiguousFailures + 1
} else if prevState.isFailure() {
// recovery, previous state was failure
failureSeconds := time.Now().Sub(prevState.TimeOfFirstFailure).Seconds()
if h.StatusListener != nil {
go h.StatusListener.HealthCheckRecovered(stateEntry, prevState.ContiguousFailures, failureSeconds)
}
}
}
|
[
"func",
"(",
"h",
"*",
"Health",
")",
"handleStatusListener",
"(",
"stateEntry",
"*",
"State",
")",
"{",
"// get the previous state",
"h",
".",
"statesLock",
".",
"Lock",
"(",
")",
"\n",
"prevState",
":=",
"h",
".",
"states",
"[",
"stateEntry",
".",
"Name",
"]",
"\n",
"h",
".",
"statesLock",
".",
"Unlock",
"(",
")",
"\n\n",
"// state is failure",
"if",
"stateEntry",
".",
"isFailure",
"(",
")",
"{",
"if",
"!",
"prevState",
".",
"isFailure",
"(",
")",
"{",
"// new failure: previous state was ok",
"if",
"h",
".",
"StatusListener",
"!=",
"nil",
"{",
"go",
"h",
".",
"StatusListener",
".",
"HealthCheckFailed",
"(",
"stateEntry",
")",
"\n",
"}",
"\n\n",
"stateEntry",
".",
"TimeOfFirstFailure",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"else",
"{",
"// carry the time of first failure from the previous state",
"stateEntry",
".",
"TimeOfFirstFailure",
"=",
"prevState",
".",
"TimeOfFirstFailure",
"\n",
"}",
"\n",
"stateEntry",
".",
"ContiguousFailures",
"=",
"prevState",
".",
"ContiguousFailures",
"+",
"1",
"\n",
"}",
"else",
"if",
"prevState",
".",
"isFailure",
"(",
")",
"{",
"// recovery, previous state was failure",
"failureSeconds",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"prevState",
".",
"TimeOfFirstFailure",
")",
".",
"Seconds",
"(",
")",
"\n\n",
"if",
"h",
".",
"StatusListener",
"!=",
"nil",
"{",
"go",
"h",
".",
"StatusListener",
".",
"HealthCheckRecovered",
"(",
"stateEntry",
",",
"prevState",
".",
"ContiguousFailures",
",",
"failureSeconds",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// if a status listener is attached
|
[
"if",
"a",
"status",
"listener",
"is",
"attached"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/health.go#L336-L364
|
20,274
|
InVisionApp/go-health
|
checkers/redis/redis.go
|
Status
|
func (r *Redis) Status() (interface{}, error) {
if r.Config.Ping {
if _, err := r.client.Ping().Result(); err != nil {
return nil, fmt.Errorf("Ping failed: %v", err)
}
}
if r.Config.Set != nil {
err := r.client.Set(r.Config.Set.Key, r.Config.Set.Value, r.Config.Set.Expiration).Err()
if err != nil {
return nil, fmt.Errorf("Unable to complete set: %v", err)
}
}
if r.Config.Get != nil {
val, err := r.client.Get(r.Config.Get.Key).Result()
if err != nil {
if err == redis.Nil {
if !r.Config.Get.NoErrorMissingKey {
return nil, fmt.Errorf("Unable to complete get: '%v' not found", r.Config.Get.Key)
}
} else {
return nil, fmt.Errorf("Unable to complete get: %v", err)
}
}
if r.Config.Get.Expect != "" {
if r.Config.Get.Expect != val {
return nil, fmt.Errorf("Unable to complete get: returned value '%v' does not match expected value '%v'",
val, r.Config.Get.Expect)
}
}
}
return nil, nil
}
|
go
|
func (r *Redis) Status() (interface{}, error) {
if r.Config.Ping {
if _, err := r.client.Ping().Result(); err != nil {
return nil, fmt.Errorf("Ping failed: %v", err)
}
}
if r.Config.Set != nil {
err := r.client.Set(r.Config.Set.Key, r.Config.Set.Value, r.Config.Set.Expiration).Err()
if err != nil {
return nil, fmt.Errorf("Unable to complete set: %v", err)
}
}
if r.Config.Get != nil {
val, err := r.client.Get(r.Config.Get.Key).Result()
if err != nil {
if err == redis.Nil {
if !r.Config.Get.NoErrorMissingKey {
return nil, fmt.Errorf("Unable to complete get: '%v' not found", r.Config.Get.Key)
}
} else {
return nil, fmt.Errorf("Unable to complete get: %v", err)
}
}
if r.Config.Get.Expect != "" {
if r.Config.Get.Expect != val {
return nil, fmt.Errorf("Unable to complete get: returned value '%v' does not match expected value '%v'",
val, r.Config.Get.Expect)
}
}
}
return nil, nil
}
|
[
"func",
"(",
"r",
"*",
"Redis",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"r",
".",
"Config",
".",
"Ping",
"{",
"if",
"_",
",",
"err",
":=",
"r",
".",
"client",
".",
"Ping",
"(",
")",
".",
"Result",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Config",
".",
"Set",
"!=",
"nil",
"{",
"err",
":=",
"r",
".",
"client",
".",
"Set",
"(",
"r",
".",
"Config",
".",
"Set",
".",
"Key",
",",
"r",
".",
"Config",
".",
"Set",
".",
"Value",
",",
"r",
".",
"Config",
".",
"Set",
".",
"Expiration",
")",
".",
"Err",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Config",
".",
"Get",
"!=",
"nil",
"{",
"val",
",",
"err",
":=",
"r",
".",
"client",
".",
"Get",
"(",
"r",
".",
"Config",
".",
"Get",
".",
"Key",
")",
".",
"Result",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"redis",
".",
"Nil",
"{",
"if",
"!",
"r",
".",
"Config",
".",
"Get",
".",
"NoErrorMissingKey",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Config",
".",
"Get",
".",
"Key",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Config",
".",
"Get",
".",
"Expect",
"!=",
"\"",
"\"",
"{",
"if",
"r",
".",
"Config",
".",
"Get",
".",
"Expect",
"!=",
"val",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
",",
"r",
".",
"Config",
".",
"Get",
".",
"Expect",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// Status is used for performing a redis check against a dependency; it satisfies
// the "ICheckable" interface.
|
[
"Status",
"is",
"used",
"for",
"performing",
"a",
"redis",
"check",
"against",
"a",
"dependency",
";",
"it",
"satisfies",
"the",
"ICheckable",
"interface",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/redis/redis.go#L111-L146
|
20,275
|
InVisionApp/go-health
|
checkers/reachable.go
|
NewReachableChecker
|
func NewReachableChecker(cfg *ReachableConfig) (*ReachableChecker, error) {
t := ReachableDefaultTimeout
if cfg.Timeout != 0 {
t = cfg.Timeout
}
d := net.DialTimeout
if cfg.Dialer != nil {
d = cfg.Dialer
}
n := ReachableDefaultNetwork
if cfg.Network != "" {
n = cfg.Network
}
r := &ReachableChecker{
dialer: d,
timeout: t,
network: n,
url: cfg.URL,
datadog: cfg.DatadogClient,
tags: cfg.DatadogTags,
}
return r, nil
}
|
go
|
func NewReachableChecker(cfg *ReachableConfig) (*ReachableChecker, error) {
t := ReachableDefaultTimeout
if cfg.Timeout != 0 {
t = cfg.Timeout
}
d := net.DialTimeout
if cfg.Dialer != nil {
d = cfg.Dialer
}
n := ReachableDefaultNetwork
if cfg.Network != "" {
n = cfg.Network
}
r := &ReachableChecker{
dialer: d,
timeout: t,
network: n,
url: cfg.URL,
datadog: cfg.DatadogClient,
tags: cfg.DatadogTags,
}
return r, nil
}
|
[
"func",
"NewReachableChecker",
"(",
"cfg",
"*",
"ReachableConfig",
")",
"(",
"*",
"ReachableChecker",
",",
"error",
")",
"{",
"t",
":=",
"ReachableDefaultTimeout",
"\n",
"if",
"cfg",
".",
"Timeout",
"!=",
"0",
"{",
"t",
"=",
"cfg",
".",
"Timeout",
"\n",
"}",
"\n",
"d",
":=",
"net",
".",
"DialTimeout",
"\n",
"if",
"cfg",
".",
"Dialer",
"!=",
"nil",
"{",
"d",
"=",
"cfg",
".",
"Dialer",
"\n",
"}",
"\n",
"n",
":=",
"ReachableDefaultNetwork",
"\n",
"if",
"cfg",
".",
"Network",
"!=",
"\"",
"\"",
"{",
"n",
"=",
"cfg",
".",
"Network",
"\n",
"}",
"\n",
"r",
":=",
"&",
"ReachableChecker",
"{",
"dialer",
":",
"d",
",",
"timeout",
":",
"t",
",",
"network",
":",
"n",
",",
"url",
":",
"cfg",
".",
"URL",
",",
"datadog",
":",
"cfg",
".",
"DatadogClient",
",",
"tags",
":",
"cfg",
".",
"DatadogTags",
",",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] |
// NewReachableChecker creates a new reachable health checker
|
[
"NewReachableChecker",
"creates",
"a",
"new",
"reachable",
"health",
"checker"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/reachable.go#L65-L87
|
20,276
|
InVisionApp/go-health
|
checkers/reachable.go
|
Status
|
func (r *ReachableChecker) Status() (interface{}, error) {
// We must provide a port so when a port is not set in the URL provided use
// the default port (80)
port := r.url.Port()
if len(port) == 0 {
port = ReachableDefaultPort
}
conn, err := r.dialer(r.network, r.url.Hostname()+":"+port, r.timeout)
if err != nil {
return r.fail(err)
}
if conn != nil {
if errClose := conn.Close(); errClose != nil {
return r.fail(errClose)
}
}
return nil, nil
}
|
go
|
func (r *ReachableChecker) Status() (interface{}, error) {
// We must provide a port so when a port is not set in the URL provided use
// the default port (80)
port := r.url.Port()
if len(port) == 0 {
port = ReachableDefaultPort
}
conn, err := r.dialer(r.network, r.url.Hostname()+":"+port, r.timeout)
if err != nil {
return r.fail(err)
}
if conn != nil {
if errClose := conn.Close(); errClose != nil {
return r.fail(errClose)
}
}
return nil, nil
}
|
[
"func",
"(",
"r",
"*",
"ReachableChecker",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// We must provide a port so when a port is not set in the URL provided use",
"// the default port (80)",
"port",
":=",
"r",
".",
"url",
".",
"Port",
"(",
")",
"\n",
"if",
"len",
"(",
"port",
")",
"==",
"0",
"{",
"port",
"=",
"ReachableDefaultPort",
"\n",
"}",
"\n\n",
"conn",
",",
"err",
":=",
"r",
".",
"dialer",
"(",
"r",
".",
"network",
",",
"r",
".",
"url",
".",
"Hostname",
"(",
")",
"+",
"\"",
"\"",
"+",
"port",
",",
"r",
".",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
".",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"conn",
"!=",
"nil",
"{",
"if",
"errClose",
":=",
"conn",
".",
"Close",
"(",
")",
";",
"errClose",
"!=",
"nil",
"{",
"return",
"r",
".",
"fail",
"(",
"errClose",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// Status checks if the endpoint is reachable
|
[
"Status",
"checks",
"if",
"the",
"endpoint",
"is",
"reachable"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/reachable.go#L90-L108
|
20,277
|
InVisionApp/go-health
|
checkers/http.go
|
Status
|
func (h *HTTP) Status() (interface{}, error) {
resp, err := h.do()
if err != nil {
return nil, err
}
defer resp.Body.Close()
// Check if StatusCode matches
if resp.StatusCode != h.Config.StatusCode {
return nil, fmt.Errorf("Received status code '%v' does not match expected status code '%v'",
resp.StatusCode, h.Config.StatusCode)
}
// If Expect is set, verify if returned response contains expected data
if h.Config.Expect != "" {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Unable to read response body to perform content expectancy check: %v", err)
}
if !strings.Contains(string(data), h.Config.Expect) {
return nil, fmt.Errorf("Received response body '%v' does not contain expected content '%v'",
string(data), h.Config.Expect)
}
}
return nil, nil
}
|
go
|
func (h *HTTP) Status() (interface{}, error) {
resp, err := h.do()
if err != nil {
return nil, err
}
defer resp.Body.Close()
// Check if StatusCode matches
if resp.StatusCode != h.Config.StatusCode {
return nil, fmt.Errorf("Received status code '%v' does not match expected status code '%v'",
resp.StatusCode, h.Config.StatusCode)
}
// If Expect is set, verify if returned response contains expected data
if h.Config.Expect != "" {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Unable to read response body to perform content expectancy check: %v", err)
}
if !strings.Contains(string(data), h.Config.Expect) {
return nil, fmt.Errorf("Received response body '%v' does not contain expected content '%v'",
string(data), h.Config.Expect)
}
}
return nil, nil
}
|
[
"func",
"(",
"h",
"*",
"HTTP",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"h",
".",
"do",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Check if StatusCode matches",
"if",
"resp",
".",
"StatusCode",
"!=",
"h",
".",
"Config",
".",
"StatusCode",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
",",
"h",
".",
"Config",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"// If Expect is set, verify if returned response contains expected data",
"if",
"h",
".",
"Config",
".",
"Expect",
"!=",
"\"",
"\"",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"string",
"(",
"data",
")",
",",
"h",
".",
"Config",
".",
"Expect",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"data",
")",
",",
"h",
".",
"Config",
".",
"Expect",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// Status is used for performing an HTTP check against a dependency; it satisfies
// the "ICheckable" interface.
|
[
"Status",
"is",
"used",
"for",
"performing",
"an",
"HTTP",
"check",
"against",
"a",
"dependency",
";",
"it",
"satisfies",
"the",
"ICheckable",
"interface",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/http.go#L66-L93
|
20,278
|
InVisionApp/go-health
|
checkers/sql.go
|
DefaultQueryHandler
|
func DefaultQueryHandler(rows *sql.Rows) (bool, error) {
defer rows.Close()
numRows := 0
for rows.Next() {
numRows++
}
return numRows == 1, nil
}
|
go
|
func DefaultQueryHandler(rows *sql.Rows) (bool, error) {
defer rows.Close()
numRows := 0
for rows.Next() {
numRows++
}
return numRows == 1, nil
}
|
[
"func",
"DefaultQueryHandler",
"(",
"rows",
"*",
"sql",
".",
"Rows",
")",
"(",
"bool",
",",
"error",
")",
"{",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"numRows",
":=",
"0",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"numRows",
"++",
"\n",
"}",
"\n\n",
"return",
"numRows",
"==",
"1",
",",
"nil",
"\n",
"}"
] |
// DefaultQueryHandler is the default SQLQueryer result handler
// that assumes one row was returned from the passed query
|
[
"DefaultQueryHandler",
"is",
"the",
"default",
"SQLQueryer",
"result",
"handler",
"that",
"assumes",
"one",
"row",
"was",
"returned",
"from",
"the",
"passed",
"query"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L102-L111
|
20,279
|
InVisionApp/go-health
|
checkers/sql.go
|
DefaultExecHandler
|
func DefaultExecHandler(result sql.Result) (bool, error) {
affectedRows, err := result.RowsAffected()
if err != nil {
return false, err
}
return affectedRows == int64(1), nil
}
|
go
|
func DefaultExecHandler(result sql.Result) (bool, error) {
affectedRows, err := result.RowsAffected()
if err != nil {
return false, err
}
return affectedRows == int64(1), nil
}
|
[
"func",
"DefaultExecHandler",
"(",
"result",
"sql",
".",
"Result",
")",
"(",
"bool",
",",
"error",
")",
"{",
"affectedRows",
",",
"err",
":=",
"result",
".",
"RowsAffected",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"affectedRows",
"==",
"int64",
"(",
"1",
")",
",",
"nil",
"\n",
"}"
] |
// DefaultExecHandler is the default SQLExecer result handler
// that assumes one row was affected in the passed query
|
[
"DefaultExecHandler",
"is",
"the",
"default",
"SQLExecer",
"result",
"handler",
"that",
"assumes",
"one",
"row",
"was",
"affected",
"in",
"the",
"passed",
"query"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L115-L122
|
20,280
|
InVisionApp/go-health
|
checkers/sql.go
|
validateSQLConfig
|
func validateSQLConfig(cfg *SQLConfig) error {
if cfg == nil {
return fmt.Errorf("config is required")
}
if cfg.Execer == nil && cfg.Queryer == nil && cfg.Pinger == nil {
return fmt.Errorf("one of Execer, Queryer, or Pinger is required in SQLConfig")
}
if (cfg.Execer != nil || cfg.Queryer != nil) && len(cfg.Query) == 0 {
return fmt.Errorf("SQLConfig.Query is required")
}
return nil
}
|
go
|
func validateSQLConfig(cfg *SQLConfig) error {
if cfg == nil {
return fmt.Errorf("config is required")
}
if cfg.Execer == nil && cfg.Queryer == nil && cfg.Pinger == nil {
return fmt.Errorf("one of Execer, Queryer, or Pinger is required in SQLConfig")
}
if (cfg.Execer != nil || cfg.Queryer != nil) && len(cfg.Query) == 0 {
return fmt.Errorf("SQLConfig.Query is required")
}
return nil
}
|
[
"func",
"validateSQLConfig",
"(",
"cfg",
"*",
"SQLConfig",
")",
"error",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"cfg",
".",
"Execer",
"==",
"nil",
"&&",
"cfg",
".",
"Queryer",
"==",
"nil",
"&&",
"cfg",
".",
"Pinger",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"(",
"cfg",
".",
"Execer",
"!=",
"nil",
"||",
"cfg",
".",
"Queryer",
"!=",
"nil",
")",
"&&",
"len",
"(",
"cfg",
".",
"Query",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// this makes sure the sql check is properly configured
|
[
"this",
"makes",
"sure",
"the",
"sql",
"check",
"is",
"properly",
"configured"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L125-L139
|
20,281
|
InVisionApp/go-health
|
checkers/sql.go
|
Status
|
func (s *SQL) Status() (interface{}, error) {
if err := validateSQLConfig(s.Config); err != nil {
return nil, err
}
switch {
// check for SQLExecer first
case s.Config.Execer != nil:
// if the result handler is nil, use the default
if s.Config.ExecerResultHandler == nil {
s.Config.ExecerResultHandler = DefaultExecHandler
}
// run the execer
return s.runExecer()
// check for SQLQueryer next
case s.Config.Queryer != nil:
// if the result handler is nil, use the default
if s.Config.QueryerResultHandler == nil {
s.Config.QueryerResultHandler = DefaultQueryHandler
}
// run the queryer
return s.runQueryer()
// finally, must be a pinger
default:
ctx := context.Background()
return nil, s.Config.Pinger.PingContext(ctx)
}
}
|
go
|
func (s *SQL) Status() (interface{}, error) {
if err := validateSQLConfig(s.Config); err != nil {
return nil, err
}
switch {
// check for SQLExecer first
case s.Config.Execer != nil:
// if the result handler is nil, use the default
if s.Config.ExecerResultHandler == nil {
s.Config.ExecerResultHandler = DefaultExecHandler
}
// run the execer
return s.runExecer()
// check for SQLQueryer next
case s.Config.Queryer != nil:
// if the result handler is nil, use the default
if s.Config.QueryerResultHandler == nil {
s.Config.QueryerResultHandler = DefaultQueryHandler
}
// run the queryer
return s.runQueryer()
// finally, must be a pinger
default:
ctx := context.Background()
return nil, s.Config.Pinger.PingContext(ctx)
}
}
|
[
"func",
"(",
"s",
"*",
"SQL",
")",
"Status",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"err",
":=",
"validateSQLConfig",
"(",
"s",
".",
"Config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"{",
"// check for SQLExecer first",
"case",
"s",
".",
"Config",
".",
"Execer",
"!=",
"nil",
":",
"// if the result handler is nil, use the default",
"if",
"s",
".",
"Config",
".",
"ExecerResultHandler",
"==",
"nil",
"{",
"s",
".",
"Config",
".",
"ExecerResultHandler",
"=",
"DefaultExecHandler",
"\n",
"}",
"\n",
"// run the execer",
"return",
"s",
".",
"runExecer",
"(",
")",
"\n",
"// check for SQLQueryer next",
"case",
"s",
".",
"Config",
".",
"Queryer",
"!=",
"nil",
":",
"// if the result handler is nil, use the default",
"if",
"s",
".",
"Config",
".",
"QueryerResultHandler",
"==",
"nil",
"{",
"s",
".",
"Config",
".",
"QueryerResultHandler",
"=",
"DefaultQueryHandler",
"\n",
"}",
"\n",
"// run the queryer",
"return",
"s",
".",
"runQueryer",
"(",
")",
"\n",
"// finally, must be a pinger",
"default",
":",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"return",
"nil",
",",
"s",
".",
"Config",
".",
"Pinger",
".",
"PingContext",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}"
] |
// Status is used for performing a database ping against a dependency; it satisfies
// the "ICheckable" interface.
|
[
"Status",
"is",
"used",
"for",
"performing",
"a",
"database",
"ping",
"against",
"a",
"dependency",
";",
"it",
"satisfies",
"the",
"ICheckable",
"interface",
"."
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L143-L170
|
20,282
|
InVisionApp/go-health
|
checkers/sql.go
|
runExecer
|
func (s *SQL) runExecer() (interface{}, error) {
ctx := context.Background()
result, err := s.Config.Execer.ExecContext(ctx, s.Config.Query, s.Config.Params...)
if err != nil {
return nil, err
}
ok, err := s.Config.ExecerResultHandler(result)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("userland exec result handler returned false")
}
return nil, nil
}
|
go
|
func (s *SQL) runExecer() (interface{}, error) {
ctx := context.Background()
result, err := s.Config.Execer.ExecContext(ctx, s.Config.Query, s.Config.Params...)
if err != nil {
return nil, err
}
ok, err := s.Config.ExecerResultHandler(result)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("userland exec result handler returned false")
}
return nil, nil
}
|
[
"func",
"(",
"s",
"*",
"SQL",
")",
"runExecer",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"result",
",",
"err",
":=",
"s",
".",
"Config",
".",
"Execer",
".",
"ExecContext",
"(",
"ctx",
",",
"s",
".",
"Config",
".",
"Query",
",",
"s",
".",
"Config",
".",
"Params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ok",
",",
"err",
":=",
"s",
".",
"Config",
".",
"ExecerResultHandler",
"(",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// This will run the execer from the Status func
|
[
"This",
"will",
"run",
"the",
"execer",
"from",
"the",
"Status",
"func"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L173-L190
|
20,283
|
InVisionApp/go-health
|
checkers/sql.go
|
runQueryer
|
func (s *SQL) runQueryer() (interface{}, error) {
ctx := context.Background()
rows, err := s.Config.Queryer.QueryContext(ctx, s.Config.Query, s.Config.Params...)
if err != nil {
return nil, err
}
// the BYO result handler is responsible for closing the rows
ok, err := s.Config.QueryerResultHandler(rows)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("userland query result handler returned false")
}
return nil, nil
}
|
go
|
func (s *SQL) runQueryer() (interface{}, error) {
ctx := context.Background()
rows, err := s.Config.Queryer.QueryContext(ctx, s.Config.Query, s.Config.Params...)
if err != nil {
return nil, err
}
// the BYO result handler is responsible for closing the rows
ok, err := s.Config.QueryerResultHandler(rows)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("userland query result handler returned false")
}
return nil, nil
}
|
[
"func",
"(",
"s",
"*",
"SQL",
")",
"runQueryer",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"rows",
",",
"err",
":=",
"s",
".",
"Config",
".",
"Queryer",
".",
"QueryContext",
"(",
"ctx",
",",
"s",
".",
"Config",
".",
"Query",
",",
"s",
".",
"Config",
".",
"Params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// the BYO result handler is responsible for closing the rows",
"ok",
",",
"err",
":=",
"s",
".",
"Config",
".",
"QueryerResultHandler",
"(",
"rows",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// This will run the queryer from the Status func
|
[
"This",
"will",
"run",
"the",
"queryer",
"from",
"the",
"Status",
"func"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/checkers/sql.go#L193-L212
|
20,284
|
InVisionApp/go-health
|
examples/status-listener/service/service.go
|
HealthCheckRecovered
|
func (sl *HealthCheckStatusListener) HealthCheckRecovered(entry *health.State, recordedFailures int64, failureDurationSeconds float64) {
svcLogger.Printf("Recovering from %d contiguous errors, lasting %1.2f seconds: %+v", recordedFailures, failureDurationSeconds, entry)
}
|
go
|
func (sl *HealthCheckStatusListener) HealthCheckRecovered(entry *health.State, recordedFailures int64, failureDurationSeconds float64) {
svcLogger.Printf("Recovering from %d contiguous errors, lasting %1.2f seconds: %+v", recordedFailures, failureDurationSeconds, entry)
}
|
[
"func",
"(",
"sl",
"*",
"HealthCheckStatusListener",
")",
"HealthCheckRecovered",
"(",
"entry",
"*",
"health",
".",
"State",
",",
"recordedFailures",
"int64",
",",
"failureDurationSeconds",
"float64",
")",
"{",
"svcLogger",
".",
"Printf",
"(",
"\"",
"\"",
",",
"recordedFailures",
",",
"failureDurationSeconds",
",",
"entry",
")",
"\n",
"}"
] |
// HealthCheckRecovered is triggered when a health check recovers
|
[
"HealthCheckRecovered",
"is",
"triggered",
"when",
"a",
"health",
"check",
"recovers"
] |
21e799eae2a99deb884177d7c34997ddb880cbba
|
https://github.com/InVisionApp/go-health/blob/21e799eae2a99deb884177d7c34997ddb880cbba/examples/status-listener/service/service.go#L26-L28
|
20,285
|
go-playground/form
|
form_encoder.go
|
NewEncoder
|
func NewEncoder() *Encoder {
e := &Encoder{
tagName: "form",
mode: ModeImplicit,
structCache: newStructCacheMap(),
embedAnonymous: true,
}
e.dataPool = &sync.Pool{New: func() interface{} {
return &encoder{
e: e,
namespace: make([]byte, 0, 64),
}
}}
return e
}
|
go
|
func NewEncoder() *Encoder {
e := &Encoder{
tagName: "form",
mode: ModeImplicit,
structCache: newStructCacheMap(),
embedAnonymous: true,
}
e.dataPool = &sync.Pool{New: func() interface{} {
return &encoder{
e: e,
namespace: make([]byte, 0, 64),
}
}}
return e
}
|
[
"func",
"NewEncoder",
"(",
")",
"*",
"Encoder",
"{",
"e",
":=",
"&",
"Encoder",
"{",
"tagName",
":",
"\"",
"\"",
",",
"mode",
":",
"ModeImplicit",
",",
"structCache",
":",
"newStructCacheMap",
"(",
")",
",",
"embedAnonymous",
":",
"true",
",",
"}",
"\n\n",
"e",
".",
"dataPool",
"=",
"&",
"sync",
".",
"Pool",
"{",
"New",
":",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"encoder",
"{",
"e",
":",
"e",
",",
"namespace",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"64",
")",
",",
"}",
"\n",
"}",
"}",
"\n\n",
"return",
"e",
"\n",
"}"
] |
// NewEncoder creates a new encoder instance with sane defaults
|
[
"NewEncoder",
"creates",
"a",
"new",
"encoder",
"instance",
"with",
"sane",
"defaults"
] |
1174b88a8ea5deef83b10a874c5074826931ab03
|
https://github.com/go-playground/form/blob/1174b88a8ea5deef83b10a874c5074826931ab03/form_encoder.go#L56-L73
|
20,286
|
go-playground/form
|
form_encoder.go
|
Encode
|
func (e *Encoder) Encode(v interface{}) (values url.Values, err error) {
val, kind := ExtractType(reflect.ValueOf(v))
if kind == reflect.Ptr || kind == reflect.Interface || kind == reflect.Invalid {
return nil, &InvalidEncodeError{reflect.TypeOf(v)}
}
enc := e.dataPool.Get().(*encoder)
enc.values = make(url.Values)
if kind == reflect.Struct && val.Type() != timeType {
enc.traverseStruct(val, enc.namespace[0:0], -1)
} else {
enc.setFieldByType(val, enc.namespace[0:0], -1, false)
}
if len(enc.errs) > 0 {
err = enc.errs
enc.errs = nil
}
values = enc.values
e.dataPool.Put(enc)
return
}
|
go
|
func (e *Encoder) Encode(v interface{}) (values url.Values, err error) {
val, kind := ExtractType(reflect.ValueOf(v))
if kind == reflect.Ptr || kind == reflect.Interface || kind == reflect.Invalid {
return nil, &InvalidEncodeError{reflect.TypeOf(v)}
}
enc := e.dataPool.Get().(*encoder)
enc.values = make(url.Values)
if kind == reflect.Struct && val.Type() != timeType {
enc.traverseStruct(val, enc.namespace[0:0], -1)
} else {
enc.setFieldByType(val, enc.namespace[0:0], -1, false)
}
if len(enc.errs) > 0 {
err = enc.errs
enc.errs = nil
}
values = enc.values
e.dataPool.Put(enc)
return
}
|
[
"func",
"(",
"e",
"*",
"Encoder",
")",
"Encode",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"values",
"url",
".",
"Values",
",",
"err",
"error",
")",
"{",
"val",
",",
"kind",
":=",
"ExtractType",
"(",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
")",
"\n\n",
"if",
"kind",
"==",
"reflect",
".",
"Ptr",
"||",
"kind",
"==",
"reflect",
".",
"Interface",
"||",
"kind",
"==",
"reflect",
".",
"Invalid",
"{",
"return",
"nil",
",",
"&",
"InvalidEncodeError",
"{",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
"}",
"\n",
"}",
"\n\n",
"enc",
":=",
"e",
".",
"dataPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"encoder",
")",
"\n",
"enc",
".",
"values",
"=",
"make",
"(",
"url",
".",
"Values",
")",
"\n\n",
"if",
"kind",
"==",
"reflect",
".",
"Struct",
"&&",
"val",
".",
"Type",
"(",
")",
"!=",
"timeType",
"{",
"enc",
".",
"traverseStruct",
"(",
"val",
",",
"enc",
".",
"namespace",
"[",
"0",
":",
"0",
"]",
",",
"-",
"1",
")",
"\n",
"}",
"else",
"{",
"enc",
".",
"setFieldByType",
"(",
"val",
",",
"enc",
".",
"namespace",
"[",
"0",
":",
"0",
"]",
",",
"-",
"1",
",",
"false",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"enc",
".",
"errs",
")",
">",
"0",
"{",
"err",
"=",
"enc",
".",
"errs",
"\n",
"enc",
".",
"errs",
"=",
"nil",
"\n",
"}",
"\n\n",
"values",
"=",
"enc",
".",
"values",
"\n\n",
"e",
".",
"dataPool",
".",
"Put",
"(",
"enc",
")",
"\n\n",
"return",
"\n",
"}"
] |
// Encode encodes the given values and sets the corresponding struct values
|
[
"Encode",
"encodes",
"the",
"given",
"values",
"and",
"sets",
"the",
"corresponding",
"struct",
"values"
] |
1174b88a8ea5deef83b10a874c5074826931ab03
|
https://github.com/go-playground/form/blob/1174b88a8ea5deef83b10a874c5074826931ab03/form_encoder.go#L117-L144
|
20,287
|
go-playground/form
|
form_decoder.go
|
NewDecoder
|
func NewDecoder() *Decoder {
d := &Decoder{
tagName: "form",
mode: ModeImplicit,
structCache: newStructCacheMap(),
maxArraySize: 10000,
}
d.dataPool = &sync.Pool{New: func() interface{} {
return &decoder{
d: d,
namespace: make([]byte, 0, 64),
}
}}
return d
}
|
go
|
func NewDecoder() *Decoder {
d := &Decoder{
tagName: "form",
mode: ModeImplicit,
structCache: newStructCacheMap(),
maxArraySize: 10000,
}
d.dataPool = &sync.Pool{New: func() interface{} {
return &decoder{
d: d,
namespace: make([]byte, 0, 64),
}
}}
return d
}
|
[
"func",
"NewDecoder",
"(",
")",
"*",
"Decoder",
"{",
"d",
":=",
"&",
"Decoder",
"{",
"tagName",
":",
"\"",
"\"",
",",
"mode",
":",
"ModeImplicit",
",",
"structCache",
":",
"newStructCacheMap",
"(",
")",
",",
"maxArraySize",
":",
"10000",
",",
"}",
"\n\n",
"d",
".",
"dataPool",
"=",
"&",
"sync",
".",
"Pool",
"{",
"New",
":",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"decoder",
"{",
"d",
":",
"d",
",",
"namespace",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"64",
")",
",",
"}",
"\n",
"}",
"}",
"\n\n",
"return",
"d",
"\n",
"}"
] |
// NewDecoder creates a new decoder instance with sane defaults
|
[
"NewDecoder",
"creates",
"a",
"new",
"decoder",
"instance",
"with",
"sane",
"defaults"
] |
1174b88a8ea5deef83b10a874c5074826931ab03
|
https://github.com/go-playground/form/blob/1174b88a8ea5deef83b10a874c5074826931ab03/form_decoder.go#L75-L92
|
20,288
|
go-playground/form
|
util.go
|
ExtractType
|
func ExtractType(current reflect.Value) (reflect.Value, reflect.Kind) {
switch current.Kind() {
case reflect.Ptr:
if current.IsNil() {
return current, reflect.Ptr
}
return ExtractType(current.Elem())
case reflect.Interface:
if current.IsNil() {
return current, reflect.Interface
}
return ExtractType(current.Elem())
default:
return current, current.Kind()
}
}
|
go
|
func ExtractType(current reflect.Value) (reflect.Value, reflect.Kind) {
switch current.Kind() {
case reflect.Ptr:
if current.IsNil() {
return current, reflect.Ptr
}
return ExtractType(current.Elem())
case reflect.Interface:
if current.IsNil() {
return current, reflect.Interface
}
return ExtractType(current.Elem())
default:
return current, current.Kind()
}
}
|
[
"func",
"ExtractType",
"(",
"current",
"reflect",
".",
"Value",
")",
"(",
"reflect",
".",
"Value",
",",
"reflect",
".",
"Kind",
")",
"{",
"switch",
"current",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"if",
"current",
".",
"IsNil",
"(",
")",
"{",
"return",
"current",
",",
"reflect",
".",
"Ptr",
"\n",
"}",
"\n\n",
"return",
"ExtractType",
"(",
"current",
".",
"Elem",
"(",
")",
")",
"\n\n",
"case",
"reflect",
".",
"Interface",
":",
"if",
"current",
".",
"IsNil",
"(",
")",
"{",
"return",
"current",
",",
"reflect",
".",
"Interface",
"\n",
"}",
"\n\n",
"return",
"ExtractType",
"(",
"current",
".",
"Elem",
"(",
")",
")",
"\n\n",
"default",
":",
"return",
"current",
",",
"current",
".",
"Kind",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// ExtractType gets the actual underlying type of field value.
// it is exposed for use within you Custom Functions
|
[
"ExtractType",
"gets",
"the",
"actual",
"underlying",
"type",
"of",
"field",
"value",
".",
"it",
"is",
"exposed",
"for",
"use",
"within",
"you",
"Custom",
"Functions"
] |
1174b88a8ea5deef83b10a874c5074826931ab03
|
https://github.com/go-playground/form/blob/1174b88a8ea5deef83b10a874c5074826931ab03/util.go#L10-L32
|
20,289
|
go-playground/form
|
util.go
|
hasValue
|
func hasValue(field reflect.Value) bool {
switch field.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return !field.IsNil()
default:
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
}
|
go
|
func hasValue(field reflect.Value) bool {
switch field.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return !field.IsNil()
default:
return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface()
}
}
|
[
"func",
"hasValue",
"(",
"field",
"reflect",
".",
"Value",
")",
"bool",
"{",
"switch",
"field",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Chan",
",",
"reflect",
".",
"Func",
":",
"return",
"!",
"field",
".",
"IsNil",
"(",
")",
"\n",
"default",
":",
"return",
"field",
".",
"IsValid",
"(",
")",
"&&",
"field",
".",
"Interface",
"(",
")",
"!=",
"reflect",
".",
"Zero",
"(",
"field",
".",
"Type",
"(",
")",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// hasValue determines if a reflect.Value is it's default value
|
[
"hasValue",
"determines",
"if",
"a",
"reflect",
".",
"Value",
"is",
"it",
"s",
"default",
"value"
] |
1174b88a8ea5deef83b10a874c5074826931ab03
|
https://github.com/go-playground/form/blob/1174b88a8ea5deef83b10a874c5074826931ab03/util.go#L49-L56
|
20,290
|
eknkc/amber
|
compiler.go
|
New
|
func New() *Compiler {
compiler := new(Compiler)
compiler.filename = ""
compiler.tempvarIndex = 0
compiler.PrettyPrint = true
compiler.Options = DefaultOptions
compiler.mixins = make(map[string]*parser.Mixin)
return compiler
}
|
go
|
func New() *Compiler {
compiler := new(Compiler)
compiler.filename = ""
compiler.tempvarIndex = 0
compiler.PrettyPrint = true
compiler.Options = DefaultOptions
compiler.mixins = make(map[string]*parser.Mixin)
return compiler
}
|
[
"func",
"New",
"(",
")",
"*",
"Compiler",
"{",
"compiler",
":=",
"new",
"(",
"Compiler",
")",
"\n",
"compiler",
".",
"filename",
"=",
"\"",
"\"",
"\n",
"compiler",
".",
"tempvarIndex",
"=",
"0",
"\n",
"compiler",
".",
"PrettyPrint",
"=",
"true",
"\n",
"compiler",
".",
"Options",
"=",
"DefaultOptions",
"\n",
"compiler",
".",
"mixins",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"parser",
".",
"Mixin",
")",
"\n\n",
"return",
"compiler",
"\n",
"}"
] |
// New creates and initialize a new Compiler.
|
[
"New",
"creates",
"and",
"initialize",
"a",
"new",
"Compiler",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L69-L78
|
20,291
|
eknkc/amber
|
compiler.go
|
MustCompile
|
func MustCompile(input string, options Options) *template.Template {
t, err := Compile(input, options)
if err != nil {
panic(err)
}
return t
}
|
go
|
func MustCompile(input string, options Options) *template.Template {
t, err := Compile(input, options)
if err != nil {
panic(err)
}
return t
}
|
[
"func",
"MustCompile",
"(",
"input",
"string",
",",
"options",
"Options",
")",
"*",
"template",
".",
"Template",
"{",
"t",
",",
"err",
":=",
"Compile",
"(",
"input",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] |
// MustCompile is the same as Compile, except the input is assumed error free. If else, panic.
|
[
"MustCompile",
"is",
"the",
"same",
"as",
"Compile",
"except",
"the",
"input",
"is",
"assumed",
"error",
"free",
".",
"If",
"else",
"panic",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L141-L147
|
20,292
|
eknkc/amber
|
compiler.go
|
MustCompileFile
|
func MustCompileFile(filename string, options Options) *template.Template {
t, err := CompileFile(filename, options)
if err != nil {
panic(err)
}
return t
}
|
go
|
func MustCompileFile(filename string, options Options) *template.Template {
t, err := CompileFile(filename, options)
if err != nil {
panic(err)
}
return t
}
|
[
"func",
"MustCompileFile",
"(",
"filename",
"string",
",",
"options",
"Options",
")",
"*",
"template",
".",
"Template",
"{",
"t",
",",
"err",
":=",
"CompileFile",
"(",
"filename",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] |
// MustCompileFile is the same as CompileFile, except the input is assumed error free. If else, panic.
|
[
"MustCompileFile",
"is",
"the",
"same",
"as",
"CompileFile",
"except",
"the",
"input",
"is",
"assumed",
"error",
"free",
".",
"If",
"else",
"panic",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L164-L170
|
20,293
|
eknkc/amber
|
compiler.go
|
MustCompileDir
|
func MustCompileDir(dirname string, dopt DirOptions, opt Options) map[string]*template.Template {
m, err := CompileDir(dirname, dopt, opt)
if err != nil {
panic(err)
}
return m
}
|
go
|
func MustCompileDir(dirname string, dopt DirOptions, opt Options) map[string]*template.Template {
m, err := CompileDir(dirname, dopt, opt)
if err != nil {
panic(err)
}
return m
}
|
[
"func",
"MustCompileDir",
"(",
"dirname",
"string",
",",
"dopt",
"DirOptions",
",",
"opt",
"Options",
")",
"map",
"[",
"string",
"]",
"*",
"template",
".",
"Template",
"{",
"m",
",",
"err",
":=",
"CompileDir",
"(",
"dirname",
",",
"dopt",
",",
"opt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] |
// MustCompileDir is the same as CompileDir, except input is assumed error free. If else, panic.
|
[
"MustCompileDir",
"is",
"the",
"same",
"as",
"CompileDir",
"except",
"input",
"is",
"assumed",
"error",
"free",
".",
"If",
"else",
"panic",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L231-L237
|
20,294
|
eknkc/amber
|
compiler.go
|
ParseData
|
func (c *Compiler) ParseData(input []byte, filename string) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.New(r.(string))
}
}()
parser, err := parser.ByteParser(input)
parser.SetFilename(filename)
if c.VirtualFilesystem != nil {
parser.SetVirtualFilesystem(c.VirtualFilesystem)
}
if err != nil {
return
}
c.node = parser.Parse()
return
}
|
go
|
func (c *Compiler) ParseData(input []byte, filename string) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.New(r.(string))
}
}()
parser, err := parser.ByteParser(input)
parser.SetFilename(filename)
if c.VirtualFilesystem != nil {
parser.SetVirtualFilesystem(c.VirtualFilesystem)
}
if err != nil {
return
}
c.node = parser.Parse()
return
}
|
[
"func",
"(",
"c",
"*",
"Compiler",
")",
"ParseData",
"(",
"input",
"[",
"]",
"byte",
",",
"filename",
"string",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"r",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"parser",
",",
"err",
":=",
"parser",
".",
"ByteParser",
"(",
"input",
")",
"\n",
"parser",
".",
"SetFilename",
"(",
"filename",
")",
"\n",
"if",
"c",
".",
"VirtualFilesystem",
"!=",
"nil",
"{",
"parser",
".",
"SetVirtualFilesystem",
"(",
"c",
".",
"VirtualFilesystem",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"node",
"=",
"parser",
".",
"Parse",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// Parse given raw amber template bytes, and the filename that belongs with it
|
[
"Parse",
"given",
"raw",
"amber",
"template",
"bytes",
"and",
"the",
"filename",
"that",
"belongs",
"with",
"it"
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L258-L277
|
20,295
|
eknkc/amber
|
compiler.go
|
ParseFile
|
func (c *Compiler) ParseFile(filename string) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.New(r.(string))
}
}()
p, err := parser.FileParser(filename)
if err != nil && c.VirtualFilesystem != nil {
p, err = parser.VirtualFileParser(filename, c.VirtualFilesystem)
}
if err != nil {
return
}
c.node = p.Parse()
c.filename = filename
return
}
|
go
|
func (c *Compiler) ParseFile(filename string) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.New(r.(string))
}
}()
p, err := parser.FileParser(filename)
if err != nil && c.VirtualFilesystem != nil {
p, err = parser.VirtualFileParser(filename, c.VirtualFilesystem)
}
if err != nil {
return
}
c.node = p.Parse()
c.filename = filename
return
}
|
[
"func",
"(",
"c",
"*",
"Compiler",
")",
"ParseFile",
"(",
"filename",
"string",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"r",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"p",
",",
"err",
":=",
"parser",
".",
"FileParser",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"c",
".",
"VirtualFilesystem",
"!=",
"nil",
"{",
"p",
",",
"err",
"=",
"parser",
".",
"VirtualFileParser",
"(",
"filename",
",",
"c",
".",
"VirtualFilesystem",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"node",
"=",
"p",
".",
"Parse",
"(",
")",
"\n",
"c",
".",
"filename",
"=",
"filename",
"\n",
"return",
"\n",
"}"
] |
// ParseFile parses the amber template file in given path.
|
[
"ParseFile",
"parses",
"the",
"amber",
"template",
"file",
"in",
"given",
"path",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L280-L298
|
20,296
|
eknkc/amber
|
compiler.go
|
CompileWithName
|
func (c *Compiler) CompileWithName(name string) (*template.Template, error) {
return c.CompileWithTemplate(template.New(name))
}
|
go
|
func (c *Compiler) CompileWithName(name string) (*template.Template, error) {
return c.CompileWithTemplate(template.New(name))
}
|
[
"func",
"(",
"c",
"*",
"Compiler",
")",
"CompileWithName",
"(",
"name",
"string",
")",
"(",
"*",
"template",
".",
"Template",
",",
"error",
")",
"{",
"return",
"c",
".",
"CompileWithTemplate",
"(",
"template",
".",
"New",
"(",
"name",
")",
")",
"\n",
"}"
] |
// CompileWithName is the same as Compile, but allows to specify a name for the template.
|
[
"CompileWithName",
"is",
"the",
"same",
"as",
"Compile",
"but",
"allows",
"to",
"specify",
"a",
"name",
"for",
"the",
"template",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L307-L309
|
20,297
|
eknkc/amber
|
compiler.go
|
CompileWithTemplate
|
func (c *Compiler) CompileWithTemplate(t *template.Template) (*template.Template, error) {
data, err := c.CompileString()
if err != nil {
return nil, err
}
tpl, err := t.Funcs(FuncMap).Parse(data)
if err != nil {
return nil, err
}
return tpl, nil
}
|
go
|
func (c *Compiler) CompileWithTemplate(t *template.Template) (*template.Template, error) {
data, err := c.CompileString()
if err != nil {
return nil, err
}
tpl, err := t.Funcs(FuncMap).Parse(data)
if err != nil {
return nil, err
}
return tpl, nil
}
|
[
"func",
"(",
"c",
"*",
"Compiler",
")",
"CompileWithTemplate",
"(",
"t",
"*",
"template",
".",
"Template",
")",
"(",
"*",
"template",
".",
"Template",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"c",
".",
"CompileString",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tpl",
",",
"err",
":=",
"t",
".",
"Funcs",
"(",
"FuncMap",
")",
".",
"Parse",
"(",
"data",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"tpl",
",",
"nil",
"\n",
"}"
] |
// CompileWithTemplate is the same as Compile but allows to specify a template.
|
[
"CompileWithTemplate",
"is",
"the",
"same",
"as",
"Compile",
"but",
"allows",
"to",
"specify",
"a",
"template",
"."
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/compiler.go#L312-L326
|
20,298
|
eknkc/amber
|
parser/scanner.go
|
Next
|
func (s *scanner) Next() *token {
if s.readRaw {
s.readRaw = false
return s.NextRaw()
}
s.ensureBuffer()
if stashed := s.stash.Front(); stashed != nil {
tok := stashed.Value.(*token)
s.stash.Remove(stashed)
return tok
}
switch s.state {
case scnEOF:
if outdent := s.indentStack.Back(); outdent != nil {
s.indentStack.Remove(outdent)
return &token{tokOutdent, "", nil}
}
return &token{tokEOF, "", nil}
case scnNewLine:
s.state = scnLine
if tok := s.scanIndent(); tok != nil {
return tok
}
return s.Next()
case scnLine:
if tok := s.scanMixin(); tok != nil {
return tok
}
if tok := s.scanMixinCall(); tok != nil {
return tok
}
if tok := s.scanDoctype(); tok != nil {
return tok
}
if tok := s.scanCondition(); tok != nil {
return tok
}
if tok := s.scanEach(); tok != nil {
return tok
}
if tok := s.scanImport(); tok != nil {
return tok
}
if tok := s.scanExtends(); tok != nil {
return tok
}
if tok := s.scanBlock(); tok != nil {
return tok
}
if tok := s.scanAssignment(); tok != nil {
return tok
}
if tok := s.scanTag(); tok != nil {
return tok
}
if tok := s.scanId(); tok != nil {
return tok
}
if tok := s.scanClassName(); tok != nil {
return tok
}
if tok := s.scanAttribute(); tok != nil {
return tok
}
if tok := s.scanComment(); tok != nil {
return tok
}
if tok := s.scanText(); tok != nil {
return tok
}
}
return nil
}
|
go
|
func (s *scanner) Next() *token {
if s.readRaw {
s.readRaw = false
return s.NextRaw()
}
s.ensureBuffer()
if stashed := s.stash.Front(); stashed != nil {
tok := stashed.Value.(*token)
s.stash.Remove(stashed)
return tok
}
switch s.state {
case scnEOF:
if outdent := s.indentStack.Back(); outdent != nil {
s.indentStack.Remove(outdent)
return &token{tokOutdent, "", nil}
}
return &token{tokEOF, "", nil}
case scnNewLine:
s.state = scnLine
if tok := s.scanIndent(); tok != nil {
return tok
}
return s.Next()
case scnLine:
if tok := s.scanMixin(); tok != nil {
return tok
}
if tok := s.scanMixinCall(); tok != nil {
return tok
}
if tok := s.scanDoctype(); tok != nil {
return tok
}
if tok := s.scanCondition(); tok != nil {
return tok
}
if tok := s.scanEach(); tok != nil {
return tok
}
if tok := s.scanImport(); tok != nil {
return tok
}
if tok := s.scanExtends(); tok != nil {
return tok
}
if tok := s.scanBlock(); tok != nil {
return tok
}
if tok := s.scanAssignment(); tok != nil {
return tok
}
if tok := s.scanTag(); tok != nil {
return tok
}
if tok := s.scanId(); tok != nil {
return tok
}
if tok := s.scanClassName(); tok != nil {
return tok
}
if tok := s.scanAttribute(); tok != nil {
return tok
}
if tok := s.scanComment(); tok != nil {
return tok
}
if tok := s.scanText(); tok != nil {
return tok
}
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"scanner",
")",
"Next",
"(",
")",
"*",
"token",
"{",
"if",
"s",
".",
"readRaw",
"{",
"s",
".",
"readRaw",
"=",
"false",
"\n",
"return",
"s",
".",
"NextRaw",
"(",
")",
"\n",
"}",
"\n\n",
"s",
".",
"ensureBuffer",
"(",
")",
"\n\n",
"if",
"stashed",
":=",
"s",
".",
"stash",
".",
"Front",
"(",
")",
";",
"stashed",
"!=",
"nil",
"{",
"tok",
":=",
"stashed",
".",
"Value",
".",
"(",
"*",
"token",
")",
"\n",
"s",
".",
"stash",
".",
"Remove",
"(",
"stashed",
")",
"\n",
"return",
"tok",
"\n",
"}",
"\n\n",
"switch",
"s",
".",
"state",
"{",
"case",
"scnEOF",
":",
"if",
"outdent",
":=",
"s",
".",
"indentStack",
".",
"Back",
"(",
")",
";",
"outdent",
"!=",
"nil",
"{",
"s",
".",
"indentStack",
".",
"Remove",
"(",
"outdent",
")",
"\n",
"return",
"&",
"token",
"{",
"tokOutdent",
",",
"\"",
"\"",
",",
"nil",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"token",
"{",
"tokEOF",
",",
"\"",
"\"",
",",
"nil",
"}",
"\n",
"case",
"scnNewLine",
":",
"s",
".",
"state",
"=",
"scnLine",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanIndent",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"Next",
"(",
")",
"\n",
"case",
"scnLine",
":",
"if",
"tok",
":=",
"s",
".",
"scanMixin",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanMixinCall",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanDoctype",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanCondition",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanEach",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanImport",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanExtends",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanBlock",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanAssignment",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanTag",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanId",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanClassName",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanAttribute",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanComment",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n\n",
"if",
"tok",
":=",
"s",
".",
"scanText",
"(",
")",
";",
"tok",
"!=",
"nil",
"{",
"return",
"tok",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Returns next token found in buffer
|
[
"Returns",
"next",
"token",
"found",
"in",
"buffer"
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/parser/scanner.go#L80-L173
|
20,299
|
eknkc/amber
|
parser/scanner.go
|
ensureBuffer
|
func (s *scanner) ensureBuffer() {
if len(s.buffer) > 0 {
return
}
buf, err := s.reader.ReadString('\n')
if err != nil && err != io.EOF {
panic(err)
} else if err != nil && len(buf) == 0 {
s.state = scnEOF
} else {
// endline "LF only" or "\n" use Unix, Linux, modern MacOS X, FreeBSD, BeOS, RISC OS
if buf[len(buf)-1] == '\n' {
buf = buf[:len(buf)-1]
}
// endline "CR+LF" or "\r\n" use internet protocols, DEC RT-11, Windows, CP/M, MS-DOS, OS/2, Symbian OS
if len(buf) > 0 && buf[len(buf)-1] == '\r' {
buf = buf[:len(buf)-1]
}
s.state = scnNewLine
s.buffer = buf
s.line += 1
s.col = 0
}
}
|
go
|
func (s *scanner) ensureBuffer() {
if len(s.buffer) > 0 {
return
}
buf, err := s.reader.ReadString('\n')
if err != nil && err != io.EOF {
panic(err)
} else if err != nil && len(buf) == 0 {
s.state = scnEOF
} else {
// endline "LF only" or "\n" use Unix, Linux, modern MacOS X, FreeBSD, BeOS, RISC OS
if buf[len(buf)-1] == '\n' {
buf = buf[:len(buf)-1]
}
// endline "CR+LF" or "\r\n" use internet protocols, DEC RT-11, Windows, CP/M, MS-DOS, OS/2, Symbian OS
if len(buf) > 0 && buf[len(buf)-1] == '\r' {
buf = buf[:len(buf)-1]
}
s.state = scnNewLine
s.buffer = buf
s.line += 1
s.col = 0
}
}
|
[
"func",
"(",
"s",
"*",
"scanner",
")",
"ensureBuffer",
"(",
")",
"{",
"if",
"len",
"(",
"s",
".",
"buffer",
")",
">",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"s",
".",
"reader",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"&&",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"s",
".",
"state",
"=",
"scnEOF",
"\n",
"}",
"else",
"{",
"// endline \"LF only\" or \"\\n\" use Unix, Linux, modern MacOS X, FreeBSD, BeOS, RISC OS",
"if",
"buf",
"[",
"len",
"(",
"buf",
")",
"-",
"1",
"]",
"==",
"'\\n'",
"{",
"buf",
"=",
"buf",
"[",
":",
"len",
"(",
"buf",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"// endline \"CR+LF\" or \"\\r\\n\" use internet protocols, DEC RT-11, Windows, CP/M, MS-DOS, OS/2, Symbian OS",
"if",
"len",
"(",
"buf",
")",
">",
"0",
"&&",
"buf",
"[",
"len",
"(",
"buf",
")",
"-",
"1",
"]",
"==",
"'\\r'",
"{",
"buf",
"=",
"buf",
"[",
":",
"len",
"(",
"buf",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"s",
".",
"state",
"=",
"scnNewLine",
"\n",
"s",
".",
"buffer",
"=",
"buf",
"\n",
"s",
".",
"line",
"+=",
"1",
"\n",
"s",
".",
"col",
"=",
"0",
"\n",
"}",
"\n",
"}"
] |
// Reads string into s.buffer
|
[
"Reads",
"string",
"into",
"s",
".",
"buffer"
] |
cdade1c073850f4ffc70a829e31235ea6892853b
|
https://github.com/eknkc/amber/blob/cdade1c073850f4ffc70a829e31235ea6892853b/parser/scanner.go#L475-L501
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.