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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8,500 | signintech/gopdf | gopdf.go | Rotate | func (gp *GoPdf) Rotate(angle, x, y float64) {
gp.UnitsToPointsVar(&x, &y)
gp.getContent().appendRotate(angle, x, y)
} | go | func (gp *GoPdf) Rotate(angle, x, y float64) {
gp.UnitsToPointsVar(&x, &y)
gp.getContent().appendRotate(angle, x, y)
} | [
"func",
"(",
"gp",
"*",
"GoPdf",
")",
"Rotate",
"(",
"angle",
",",
"x",
",",
"y",
"float64",
")",
"{",
"gp",
".",
"UnitsToPointsVar",
"(",
"&",
"x",
",",
"&",
"y",
")",
"\n",
"gp",
".",
"getContent",
"(",
")",
".",
"appendRotate",
"(",
"angle",
... | //Rotate rotate text or image
// angle is angle in degrees.
// x, y is rotation center | [
"Rotate",
"rotate",
"text",
"or",
"image",
"angle",
"is",
"angle",
"in",
"degrees",
".",
"x",
"y",
"is",
"rotation",
"center"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/gopdf.go#L761-L764 |
8,501 | signintech/gopdf | gopdf.go | UnitsToPoints | func (gp *GoPdf) UnitsToPoints(u float64) float64 {
return UnitsToPoints(gp.config.Unit, u)
} | go | func (gp *GoPdf) UnitsToPoints(u float64) float64 {
return UnitsToPoints(gp.config.Unit, u)
} | [
"func",
"(",
"gp",
"*",
"GoPdf",
")",
"UnitsToPoints",
"(",
"u",
"float64",
")",
"float64",
"{",
"return",
"UnitsToPoints",
"(",
"gp",
".",
"config",
".",
"Unit",
",",
"u",
")",
"\n",
"}"
] | // UnitsToPoints converts the units to the documents unit type | [
"UnitsToPoints",
"converts",
"the",
"units",
"to",
"the",
"documents",
"unit",
"type"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/gopdf.go#L815-L817 |
8,502 | signintech/gopdf | gopdf.go | UnitsToPointsVar | func (gp *GoPdf) UnitsToPointsVar(u ...*float64) {
UnitsToPointsVar(gp.config.Unit, u...)
} | go | func (gp *GoPdf) UnitsToPointsVar(u ...*float64) {
UnitsToPointsVar(gp.config.Unit, u...)
} | [
"func",
"(",
"gp",
"*",
"GoPdf",
")",
"UnitsToPointsVar",
"(",
"u",
"...",
"*",
"float64",
")",
"{",
"UnitsToPointsVar",
"(",
"gp",
".",
"config",
".",
"Unit",
",",
"u",
"...",
")",
"\n",
"}"
] | // UnitsToPointsVar converts the units to the documents unit type for all variables passed in | [
"UnitsToPointsVar",
"converts",
"the",
"units",
"to",
"the",
"documents",
"unit",
"type",
"for",
"all",
"variables",
"passed",
"in"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/gopdf.go#L820-L822 |
8,503 | signintech/gopdf | gopdf.go | PointsToUnits | func (gp *GoPdf) PointsToUnits(u float64) float64 {
return PointsToUnits(gp.config.Unit, u)
} | go | func (gp *GoPdf) PointsToUnits(u float64) float64 {
return PointsToUnits(gp.config.Unit, u)
} | [
"func",
"(",
"gp",
"*",
"GoPdf",
")",
"PointsToUnits",
"(",
"u",
"float64",
")",
"float64",
"{",
"return",
"PointsToUnits",
"(",
"gp",
".",
"config",
".",
"Unit",
",",
"u",
")",
"\n",
"}"
] | // PointsToUnits converts the points to the documents unit type | [
"PointsToUnits",
"converts",
"the",
"points",
"to",
"the",
"documents",
"unit",
"type"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/gopdf.go#L825-L827 |
8,504 | signintech/gopdf | gopdf.go | PointsToUnitsVar | func (gp *GoPdf) PointsToUnitsVar(u ...*float64) {
PointsToUnitsVar(gp.config.Unit, u...)
} | go | func (gp *GoPdf) PointsToUnitsVar(u ...*float64) {
PointsToUnitsVar(gp.config.Unit, u...)
} | [
"func",
"(",
"gp",
"*",
"GoPdf",
")",
"PointsToUnitsVar",
"(",
"u",
"...",
"*",
"float64",
")",
"{",
"PointsToUnitsVar",
"(",
"gp",
".",
"config",
".",
"Unit",
",",
"u",
"...",
")",
"\n",
"}"
] | //PointsToUnitsVar converts the points to the documents unit type for all variables passed in | [
"PointsToUnitsVar",
"converts",
"the",
"points",
"to",
"the",
"documents",
"unit",
"type",
"for",
"all",
"variables",
"passed",
"in"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/gopdf.go#L830-L832 |
8,505 | signintech/gopdf | rect.go | PointsToUnits | func (rect *Rect) PointsToUnits(t int) (r *Rect) {
if rect == nil {
return
}
if rect.unitOverride != Unit_Unset {
t = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
PointsToUnitsVar(t, &r.W, &r.H)
return
} | go | func (rect *Rect) PointsToUnits(t int) (r *Rect) {
if rect == nil {
return
}
if rect.unitOverride != Unit_Unset {
t = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
PointsToUnitsVar(t, &r.W, &r.H)
return
} | [
"func",
"(",
"rect",
"*",
"Rect",
")",
"PointsToUnits",
"(",
"t",
"int",
")",
"(",
"r",
"*",
"Rect",
")",
"{",
"if",
"rect",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"rect",
".",
"unitOverride",
"!=",
"Unit_Unset",
"{",
"t",
"=",
"rec... | // PointsToUnits converts the rectanlges width and height to Units. When this is called it is assumed the values of the rectangle are in Points | [
"PointsToUnits",
"converts",
"the",
"rectanlges",
"width",
"and",
"height",
"to",
"Units",
".",
"When",
"this",
"is",
"called",
"it",
"is",
"assumed",
"the",
"values",
"of",
"the",
"rectangle",
"are",
"in",
"Points"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/rect.go#L10-L22 |
8,506 | signintech/gopdf | rect.go | UnitsToPoints | func (rect *Rect) UnitsToPoints(t int) (r *Rect) {
if rect == nil {
return
}
if rect.unitOverride != Unit_Unset {
t = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
UnitsToPointsVar(t, &r.W, &r.H)
return
} | go | func (rect *Rect) UnitsToPoints(t int) (r *Rect) {
if rect == nil {
return
}
if rect.unitOverride != Unit_Unset {
t = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
UnitsToPointsVar(t, &r.W, &r.H)
return
} | [
"func",
"(",
"rect",
"*",
"Rect",
")",
"UnitsToPoints",
"(",
"t",
"int",
")",
"(",
"r",
"*",
"Rect",
")",
"{",
"if",
"rect",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"rect",
".",
"unitOverride",
"!=",
"Unit_Unset",
"{",
"t",
"=",
"rec... | // UnitsToPoints converts the rectanlges width and height to Points. When this is called it is assumed the values of the rectangle are in Units | [
"UnitsToPoints",
"converts",
"the",
"rectanlges",
"width",
"and",
"height",
"to",
"Points",
".",
"When",
"this",
"is",
"called",
"it",
"is",
"assumed",
"the",
"values",
"of",
"the",
"rectangle",
"are",
"in",
"Units"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/rect.go#L25-L37 |
8,507 | signintech/gopdf | image_obj_parse.go | ImgReactagleToWH | func ImgReactagleToWH(imageRect image.Rectangle) (float64, float64) {
k := 1
w := -128 //init
h := -128 //init
if w < 0 {
w = -imageRect.Dx() * 72 / w / k
}
if h < 0 {
h = -imageRect.Dy() * 72 / h / k
}
if w == 0 {
w = h * imageRect.Dx() / imageRect.Dy()
}
if h == 0 {
h = w * imageRect.Dy() / imageRect.Dx()
}
return float64(w), float64(h)
} | go | func ImgReactagleToWH(imageRect image.Rectangle) (float64, float64) {
k := 1
w := -128 //init
h := -128 //init
if w < 0 {
w = -imageRect.Dx() * 72 / w / k
}
if h < 0 {
h = -imageRect.Dy() * 72 / h / k
}
if w == 0 {
w = h * imageRect.Dx() / imageRect.Dy()
}
if h == 0 {
h = w * imageRect.Dy() / imageRect.Dx()
}
return float64(w), float64(h)
} | [
"func",
"ImgReactagleToWH",
"(",
"imageRect",
"image",
".",
"Rectangle",
")",
"(",
"float64",
",",
"float64",
")",
"{",
"k",
":=",
"1",
"\n",
"w",
":=",
"-",
"128",
"//init",
"\n",
"h",
":=",
"-",
"128",
"//init",
"\n",
"if",
"w",
"<",
"0",
"{",
... | //ImgReactagleToWH Rectangle to W and H | [
"ImgReactagleToWH",
"Rectangle",
"to",
"W",
"and",
"H"
] | 5ddacf37801c86c59455989062fad631835b7583 | https://github.com/signintech/gopdf/blob/5ddacf37801c86c59455989062fad631835b7583/image_obj_parse.go#L454-L471 |
8,508 | graymeta/stow | b2/item.go | URL | func (i *item) URL() *url.URL {
str, err := i.bucket.FileURL(i.name)
if err != nil {
return nil
}
url, _ := url.Parse(str)
url.Scheme = Kind
return url
} | go | func (i *item) URL() *url.URL {
str, err := i.bucket.FileURL(i.name)
if err != nil {
return nil
}
url, _ := url.Parse(str)
url.Scheme = Kind
return url
} | [
"func",
"(",
"i",
"*",
"item",
")",
"URL",
"(",
")",
"*",
"url",
".",
"URL",
"{",
"str",
",",
"err",
":=",
"i",
".",
"bucket",
".",
"FileURL",
"(",
"i",
".",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\... | // URL returns the stow url for this item | [
"URL",
"returns",
"the",
"stow",
"url",
"for",
"this",
"item"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/item.go#L40-L50 |
8,509 | graymeta/stow | b2/item.go | Metadata | func (i *item) Metadata() (map[string]interface{}, error) {
if err := i.ensureInfo(); err != nil {
return nil, errors.Wrap(err, "retrieving item metadata")
}
return i.metadata, nil
} | go | func (i *item) Metadata() (map[string]interface{}, error) {
if err := i.ensureInfo(); err != nil {
return nil, errors.Wrap(err, "retrieving item metadata")
}
return i.metadata, nil
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Metadata",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"err",
":=",
"i",
".",
"ensureInfo",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // Metadata returns additional item metadata fields that were set when the file was uploaded | [
"Metadata",
"returns",
"additional",
"item",
"metadata",
"fields",
"that",
"were",
"set",
"when",
"the",
"file",
"was",
"uploaded"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/item.go#L53-L58 |
8,510 | graymeta/stow | b2/item.go | Open | func (i *item) Open() (io.ReadCloser, error) {
_, r, err := i.bucket.DownloadFileByName(i.name)
return r, err
} | go | func (i *item) Open() (io.ReadCloser, error) {
_, r, err := i.bucket.DownloadFileByName(i.name)
return r, err
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Open",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"_",
",",
"r",
",",
"err",
":=",
"i",
".",
"bucket",
".",
"DownloadFileByName",
"(",
"i",
".",
"name",
")",
"\n",
"return",
"r",
",",
... | // Open downloads the item | [
"Open",
"downloads",
"the",
"item"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/item.go#L66-L69 |
8,511 | graymeta/stow | b2/item.go | ETag | func (i *item) ETag() (string, error) {
if err := i.ensureInfo(); err != nil {
return "", errors.Wrap(err, "retreiving etag")
}
return i.lastModified.String(), nil
} | go | func (i *item) ETag() (string, error) {
if err := i.ensureInfo(); err != nil {
return "", errors.Wrap(err, "retreiving etag")
}
return i.lastModified.String(), nil
} | [
"func",
"(",
"i",
"*",
"item",
")",
"ETag",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"i",
".",
"ensureInfo",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",... | // ETag returns an etag for an item. In this implementation we use the file's last modified timestamp | [
"ETag",
"returns",
"an",
"etag",
"for",
"an",
"item",
".",
"In",
"this",
"implementation",
"we",
"use",
"the",
"file",
"s",
"last",
"modified",
"timestamp"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/item.go#L72-L77 |
8,512 | graymeta/stow | oracle/location.go | CreateContainer | func (l *location) CreateContainer(name string) (stow.Container, error) {
err := l.client.ContainerCreate(name, nil)
if err != nil {
return nil, err
}
container := &container{
id: name,
client: l.client,
}
return container, nil
} | go | func (l *location) CreateContainer(name string) (stow.Container, error) {
err := l.client.ContainerCreate(name, nil)
if err != nil {
return nil, err
}
container := &container{
id: name,
client: l.client,
}
return container, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"CreateContainer",
"(",
"name",
"string",
")",
"(",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"err",
":=",
"l",
".",
"client",
".",
"ContainerCreate",
"(",
"name",
",",
"nil",
")",
"\n",
"if",
"err",
... | // CreateContainer creates a new container with the given name while returning a
// container instance with the given information. | [
"CreateContainer",
"creates",
"a",
"new",
"container",
"with",
"the",
"given",
"name",
"while",
"returning",
"a",
"container",
"instance",
"with",
"the",
"given",
"information",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/location.go#L24-L34 |
8,513 | graymeta/stow | oracle/location.go | Containers | func (l *location) Containers(prefix, cursor string, count int) ([]stow.Container, string, error) {
params := &swift.ContainersOpts{
Limit: count,
Prefix: prefix,
Marker: cursor,
}
response, err := l.client.Containers(params)
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, len(response))
for i, cont := range response {
containers[i] = &container{
id: cont.Name,
client: l.client,
// count: cont.Count,
// bytes: cont.Bytes,
}
}
marker := ""
if len(response) == count {
marker = response[len(response)-1].Name
}
return containers, marker, nil
} | go | func (l *location) Containers(prefix, cursor string, count int) ([]stow.Container, string, error) {
params := &swift.ContainersOpts{
Limit: count,
Prefix: prefix,
Marker: cursor,
}
response, err := l.client.Containers(params)
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, len(response))
for i, cont := range response {
containers[i] = &container{
id: cont.Name,
client: l.client,
// count: cont.Count,
// bytes: cont.Bytes,
}
}
marker := ""
if len(response) == count {
marker = response[len(response)-1].Name
}
return containers, marker, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"Containers",
"(",
"prefix",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Container",
",",
"string",
",",
"error",
")",
"{",
"params",
":=",
"&",
"swift",
".",
"ContainersOpts... | // Containers returns a collection of containers based on the given prefix and cursor. | [
"Containers",
"returns",
"a",
"collection",
"of",
"containers",
"based",
"on",
"the",
"given",
"prefix",
"and",
"cursor",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/location.go#L37-L61 |
8,514 | graymeta/stow | oracle/location.go | Container | func (l *location) Container(id string) (stow.Container, error) {
_, _, err := l.client.Container(id)
// TODO: grab info + headers
if err != nil {
return nil, stow.ErrNotFound
}
c := &container{
id: id,
client: l.client,
}
return c, nil
} | go | func (l *location) Container(id string) (stow.Container, error) {
_, _, err := l.client.Container(id)
// TODO: grab info + headers
if err != nil {
return nil, stow.ErrNotFound
}
c := &container{
id: id,
client: l.client,
}
return c, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"Container",
"(",
"id",
"string",
")",
"(",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"_",
",",
"_",
",",
"err",
":=",
"l",
".",
"client",
".",
"Container",
"(",
"id",
")",
"\n",
"// TODO: grab info +... | // Container utilizes the client to retrieve container information based on its
// name. | [
"Container",
"utilizes",
"the",
"client",
"to",
"retrieve",
"container",
"information",
"based",
"on",
"its",
"name",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/location.go#L65-L78 |
8,515 | graymeta/stow | oracle/location.go | RemoveContainer | func (l *location) RemoveContainer(id string) error {
return l.client.ContainerDelete(id)
} | go | func (l *location) RemoveContainer(id string) error {
return l.client.ContainerDelete(id)
} | [
"func",
"(",
"l",
"*",
"location",
")",
"RemoveContainer",
"(",
"id",
"string",
")",
"error",
"{",
"return",
"l",
".",
"client",
".",
"ContainerDelete",
"(",
"id",
")",
"\n",
"}"
] | // RemoveContainer attempts to remove a container. Nonempty containers cannot
// be removed. | [
"RemoveContainer",
"attempts",
"to",
"remove",
"a",
"container",
".",
"Nonempty",
"containers",
"cannot",
"be",
"removed",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/location.go#L100-L102 |
8,516 | graymeta/stow | stow.go | Register | func Register(kind string, makefn func(Config) (Location, error), kindmatchfn func(*url.URL) bool, validatefn func(Config) error) {
lock.Lock()
defer lock.Unlock()
// if already registered, leave
if _, ok := locations[kind]; ok {
return
}
locations[kind] = makefn
configurations[kind] = validatefn
kinds = append(kinds, kind)
kindmatches = append(kindmatches, func(u *url.URL) string {
if kindmatchfn(u) {
return kind // match
}
return "" // empty string means no match
})
} | go | func Register(kind string, makefn func(Config) (Location, error), kindmatchfn func(*url.URL) bool, validatefn func(Config) error) {
lock.Lock()
defer lock.Unlock()
// if already registered, leave
if _, ok := locations[kind]; ok {
return
}
locations[kind] = makefn
configurations[kind] = validatefn
kinds = append(kinds, kind)
kindmatches = append(kindmatches, func(u *url.URL) string {
if kindmatchfn(u) {
return kind // match
}
return "" // empty string means no match
})
} | [
"func",
"Register",
"(",
"kind",
"string",
",",
"makefn",
"func",
"(",
"Config",
")",
"(",
"Location",
",",
"error",
")",
",",
"kindmatchfn",
"func",
"(",
"*",
"url",
".",
"URL",
")",
"bool",
",",
"validatefn",
"func",
"(",
"Config",
")",
"error",
")... | // Register adds a Location implementation, with two helper functions.
// makefn should make a Location with the given Config.
// kindmatchfn should inspect a URL and return whether it represents a Location
// of this kind or not. Code can call KindByURL to get a kind string
// for any given URL and all registered implementations will be consulted.
// Register is usually called in an implementation package's init method. | [
"Register",
"adds",
"a",
"Location",
"implementation",
"with",
"two",
"helper",
"functions",
".",
"makefn",
"should",
"make",
"a",
"Location",
"with",
"the",
"given",
"Config",
".",
"kindmatchfn",
"should",
"inspect",
"a",
"URL",
"and",
"return",
"whether",
"i... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/stow.go#L162-L178 |
8,517 | graymeta/stow | stow.go | Dial | func Dial(kind string, config Config) (Location, error) {
fn, ok := locations[kind]
if !ok {
return nil, errUnknownKind(kind)
}
return fn(config)
} | go | func Dial(kind string, config Config) (Location, error) {
fn, ok := locations[kind]
if !ok {
return nil, errUnknownKind(kind)
}
return fn(config)
} | [
"func",
"Dial",
"(",
"kind",
"string",
",",
"config",
"Config",
")",
"(",
"Location",
",",
"error",
")",
"{",
"fn",
",",
"ok",
":=",
"locations",
"[",
"kind",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errUnknownKind",
"(",
"kind",
")"... | // Dial gets a new Location with the given kind and
// configuration. | [
"Dial",
"gets",
"a",
"new",
"Location",
"with",
"the",
"given",
"kind",
"and",
"configuration",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/stow.go#L182-L188 |
8,518 | graymeta/stow | stow.go | Validate | func Validate(kind string, config Config) error {
fn, ok := configurations[kind]
if !ok {
return errUnknownKind(kind)
}
return fn(config)
} | go | func Validate(kind string, config Config) error {
fn, ok := configurations[kind]
if !ok {
return errUnknownKind(kind)
}
return fn(config)
} | [
"func",
"Validate",
"(",
"kind",
"string",
",",
"config",
"Config",
")",
"error",
"{",
"fn",
",",
"ok",
":=",
"configurations",
"[",
"kind",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errUnknownKind",
"(",
"kind",
")",
"\n",
"}",
"\n",
"return",
"fn... | // Validate validates the config for a location | [
"Validate",
"validates",
"the",
"config",
"for",
"a",
"location"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/stow.go#L191-L197 |
8,519 | graymeta/stow | stow.go | KindByURL | func KindByURL(u *url.URL) (string, error) {
lock.RLock()
defer lock.RUnlock()
for _, fn := range kindmatches {
kind := fn(u)
if kind == "" {
continue
}
return kind, nil
}
return "", errUnknownKind("")
} | go | func KindByURL(u *url.URL) (string, error) {
lock.RLock()
defer lock.RUnlock()
for _, fn := range kindmatches {
kind := fn(u)
if kind == "" {
continue
}
return kind, nil
}
return "", errUnknownKind("")
} | [
"func",
"KindByURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"string",
",",
"error",
")",
"{",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"fn",
":=",
"range",
"kindmatches",
"{",
... | // KindByURL gets the kind represented by the given URL.
// It consults all registered locations.
// Error returned if no match is found. | [
"KindByURL",
"gets",
"the",
"kind",
"represented",
"by",
"the",
"given",
"URL",
".",
"It",
"consults",
"all",
"registered",
"locations",
".",
"Error",
"returned",
"if",
"no",
"match",
"is",
"found",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/stow.go#L209-L220 |
8,520 | graymeta/stow | stow.go | Config | func (c ConfigMap) Config(name string) (string, bool) {
val, ok := c[name]
return val, ok
} | go | func (c ConfigMap) Config(name string) (string, bool) {
val, ok := c[name]
return val, ok
} | [
"func",
"(",
"c",
"ConfigMap",
")",
"Config",
"(",
"name",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"val",
",",
"ok",
":=",
"c",
"[",
"name",
"]",
"\n",
"return",
"val",
",",
"ok",
"\n",
"}"
] | // Config gets a string configuration value and a
// bool indicating whether the value was present or not. | [
"Config",
"gets",
"a",
"string",
"configuration",
"value",
"and",
"a",
"bool",
"indicating",
"whether",
"the",
"value",
"was",
"present",
"or",
"not",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/stow.go#L228-L231 |
8,521 | graymeta/stow | local/item.go | Open | func (i *item) Open() (io.ReadCloser, error) {
return os.Open(i.path)
} | go | func (i *item) Open() (io.ReadCloser, error) {
return os.Open(i.path)
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Open",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"os",
".",
"Open",
"(",
"i",
".",
"path",
")",
"\n",
"}"
] | // Open opens the file for reading. | [
"Open",
"opens",
"the",
"file",
"for",
"reading",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/local/item.go#L70-L72 |
8,522 | graymeta/stow | s3/item.go | URL | func (i *item) URL() *url.URL {
if i.container.customEndpoint == "" {
genericURL := fmt.Sprintf("https://s3-%s.amazonaws.com/%s/%s", i.container.Region(), i.container.Name(), i.Name())
return &url.URL{
Scheme: "s3",
Path: genericURL,
}
}
genericURL := fmt.Sprintf("%s/%s", i.container.Name(), i.Name())
return &url.URL{
Scheme: "s3",
Path: genericURL,
}
} | go | func (i *item) URL() *url.URL {
if i.container.customEndpoint == "" {
genericURL := fmt.Sprintf("https://s3-%s.amazonaws.com/%s/%s", i.container.Region(), i.container.Name(), i.Name())
return &url.URL{
Scheme: "s3",
Path: genericURL,
}
}
genericURL := fmt.Sprintf("%s/%s", i.container.Name(), i.Name())
return &url.URL{
Scheme: "s3",
Path: genericURL,
}
} | [
"func",
"(",
"i",
"*",
"item",
")",
"URL",
"(",
")",
"*",
"url",
".",
"URL",
"{",
"if",
"i",
".",
"container",
".",
"customEndpoint",
"==",
"\"",
"\"",
"{",
"genericURL",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
".",
"container",
... | // URL returns a formatted string which follows the predefined format
// that every S3 asset is given. | [
"URL",
"returns",
"a",
"formatted",
"string",
"which",
"follows",
"the",
"predefined",
"format",
"that",
"every",
"S3",
"asset",
"is",
"given",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/item.go#L65-L80 |
8,523 | graymeta/stow | s3/item.go | Open | func (i *item) Open() (io.ReadCloser, error) {
params := &s3.GetObjectInput{
Bucket: aws.String(i.container.Name()),
Key: aws.String(i.ID()),
}
response, err := i.client.GetObject(params)
if err != nil {
return nil, errors.Wrap(err, "Open, getting the object")
}
return response.Body, nil
} | go | func (i *item) Open() (io.ReadCloser, error) {
params := &s3.GetObjectInput{
Bucket: aws.String(i.container.Name()),
Key: aws.String(i.ID()),
}
response, err := i.client.GetObject(params)
if err != nil {
return nil, errors.Wrap(err, "Open, getting the object")
}
return response.Body, nil
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Open",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"params",
":=",
"&",
"s3",
".",
"GetObjectInput",
"{",
"Bucket",
":",
"aws",
".",
"String",
"(",
"i",
".",
"container",
".",
"Name",
"(",
... | // Open retrieves specic information about an item based on the container name
// and path of the file within the container. This response includes the body of
// resource which is returned along with an error. | [
"Open",
"retrieves",
"specic",
"information",
"about",
"an",
"item",
"based",
"on",
"the",
"container",
"name",
"and",
"path",
"of",
"the",
"file",
"within",
"the",
"container",
".",
"This",
"response",
"includes",
"the",
"body",
"of",
"resource",
"which",
"... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/item.go#L85-L96 |
8,524 | graymeta/stow | s3/item.go | Tags | func (i *item) Tags() (map[string]interface{}, error) {
i.tagsOnce.Do(func() {
params := &s3.GetObjectTaggingInput{
Bucket: aws.String(i.container.name),
Key: aws.String(i.ID()),
}
res, err := i.client.GetObjectTagging(params)
if err != nil {
if strings.Contains(err.Error(), "NoSuchKey") {
i.tagsErr = stow.ErrNotFound
return
}
i.tagsErr = errors.Wrap(err, "getObjectTagging")
return
}
i.tags = make(map[string]interface{})
for _, t := range res.TagSet {
i.tags[*t.Key] = *t.Value
}
})
return i.tags, i.tagsErr
} | go | func (i *item) Tags() (map[string]interface{}, error) {
i.tagsOnce.Do(func() {
params := &s3.GetObjectTaggingInput{
Bucket: aws.String(i.container.name),
Key: aws.String(i.ID()),
}
res, err := i.client.GetObjectTagging(params)
if err != nil {
if strings.Contains(err.Error(), "NoSuchKey") {
i.tagsErr = stow.ErrNotFound
return
}
i.tagsErr = errors.Wrap(err, "getObjectTagging")
return
}
i.tags = make(map[string]interface{})
for _, t := range res.TagSet {
i.tags[*t.Key] = *t.Value
}
})
return i.tags, i.tagsErr
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Tags",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"i",
".",
"tagsOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"params",
":=",
"&",
"s3",
".",
"GetObjectTaggingI... | // Tags returns a map of tags on an Item | [
"Tags",
"returns",
"a",
"map",
"of",
"tags",
"on",
"an",
"Item"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/item.go#L162-L186 |
8,525 | graymeta/stow | swift/item.go | ensureInfo | func (i *item) ensureInfo() error {
// If lastModified is empty, so is hash. get info on the Item and
// update the necessary fields at the same time.
if i.lastModified.IsZero() || i.hash == "" || i.metadata == nil {
i.infoOnce.Do(func() {
itemInfo, infoErr := i.getInfo()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.hash, i.infoErr = itemInfo.ETag()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.lastModified, i.infoErr = itemInfo.LastMod()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.metadata, i.infoErr = itemInfo.Metadata()
if infoErr != nil {
i.infoErr = infoErr
return
}
})
}
return i.infoErr
} | go | func (i *item) ensureInfo() error {
// If lastModified is empty, so is hash. get info on the Item and
// update the necessary fields at the same time.
if i.lastModified.IsZero() || i.hash == "" || i.metadata == nil {
i.infoOnce.Do(func() {
itemInfo, infoErr := i.getInfo()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.hash, i.infoErr = itemInfo.ETag()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.lastModified, i.infoErr = itemInfo.LastMod()
if infoErr != nil {
i.infoErr = infoErr
return
}
i.metadata, i.infoErr = itemInfo.Metadata()
if infoErr != nil {
i.infoErr = infoErr
return
}
})
}
return i.infoErr
} | [
"func",
"(",
"i",
"*",
"item",
")",
"ensureInfo",
"(",
")",
"error",
"{",
"// If lastModified is empty, so is hash. get info on the Item and",
"// update the necessary fields at the same time.",
"if",
"i",
".",
"lastModified",
".",
"IsZero",
"(",
")",
"||",
"i",
".",
... | // ensureInfo checks the fields that may be empty when an item is PUT.
// Verify if the fields are empty, get information on the item, fill in
// the missing fields. | [
"ensureInfo",
"checks",
"the",
"fields",
"that",
"may",
"be",
"empty",
"when",
"an",
"item",
"is",
"PUT",
".",
"Verify",
"if",
"the",
"fields",
"are",
"empty",
"get",
"information",
"on",
"the",
"item",
"fill",
"in",
"the",
"missing",
"fields",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/swift/item.go#L86-L114 |
8,526 | graymeta/stow | oracle/item.go | Open | func (i *item) Open() (io.ReadCloser, error) {
r, _, err := i.client.ObjectOpen(i.container.id, i.id, false, nil)
var res io.ReadCloser = r
// FIXME: this is a workaround to issue https://github.com/graymeta/stow/issues/120
if s, ok := res.(readSeekCloser); ok {
res = &fixReadSeekCloser{readSeekCloser: s, item: i}
}
return res, err
} | go | func (i *item) Open() (io.ReadCloser, error) {
r, _, err := i.client.ObjectOpen(i.container.id, i.id, false, nil)
var res io.ReadCloser = r
// FIXME: this is a workaround to issue https://github.com/graymeta/stow/issues/120
if s, ok := res.(readSeekCloser); ok {
res = &fixReadSeekCloser{readSeekCloser: s, item: i}
}
return res, err
} | [
"func",
"(",
"i",
"*",
"item",
")",
"Open",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"r",
",",
"_",
",",
"err",
":=",
"i",
".",
"client",
".",
"ObjectOpen",
"(",
"i",
".",
"container",
".",
"id",
",",
"i",
".",
"id",
... | // Open is a method that returns an io.ReadCloser which represents the content
// of the CloudStorage object. | [
"Open",
"is",
"a",
"method",
"that",
"returns",
"an",
"io",
".",
"ReadCloser",
"which",
"represents",
"the",
"content",
"of",
"the",
"CloudStorage",
"object",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/item.go#L57-L65 |
8,527 | graymeta/stow | oracle/item.go | LastMod | func (i *item) LastMod() (time.Time, error) {
// If an object is PUT, certain information is missing. Detect
// if the lastModified field is missing, send a request to retrieve
// it, and save both this and other missing information so that a
// request doesn't have to be sent again.
err := i.ensureInfo()
if err != nil {
return time.Time{}, err
}
return i.lastModified, nil
} | go | func (i *item) LastMod() (time.Time, error) {
// If an object is PUT, certain information is missing. Detect
// if the lastModified field is missing, send a request to retrieve
// it, and save both this and other missing information so that a
// request doesn't have to be sent again.
err := i.ensureInfo()
if err != nil {
return time.Time{}, err
}
return i.lastModified, nil
} | [
"func",
"(",
"i",
"*",
"item",
")",
"LastMod",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"// If an object is PUT, certain information is missing. Detect",
"// if the lastModified field is missing, send a request to retrieve",
"// it, and save both this and oth... | // LastMod returns a time.Time object representing information on the date
// of the last time the CloudStorage object was modified. | [
"LastMod",
"returns",
"a",
"time",
".",
"Time",
"object",
"representing",
"information",
"on",
"the",
"date",
"of",
"the",
"last",
"time",
"the",
"CloudStorage",
"object",
"was",
"modified",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/item.go#L97-L107 |
8,528 | graymeta/stow | swift/container.go | parseMetadata | func parseMetadata(md swift.Headers) (map[string]interface{}, error) {
m := make(map[string]interface{}, len(md))
for key, value := range md.ObjectMetadata() {
m[key] = value
}
return m, nil
} | go | func parseMetadata(md swift.Headers) (map[string]interface{}, error) {
m := make(map[string]interface{}, len(md))
for key, value := range md.ObjectMetadata() {
m[key] = value
}
return m, nil
} | [
"func",
"parseMetadata",
"(",
"md",
"swift",
".",
"Headers",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"md",
")",... | // Keys are returned as all lowercase, dashes are allowed | [
"Keys",
"are",
"returned",
"as",
"all",
"lowercase",
"dashes",
"are",
"allowed"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/swift/container.go#L118-L124 |
8,529 | graymeta/stow | oracle/container.go | Items | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
params := &swift.ObjectsOpts{
Limit: count,
Marker: cursor,
Prefix: prefix,
}
objects, err := c.client.Objects(c.id, params)
if err != nil {
return nil, "", err
}
items := make([]stow.Item, len(objects))
for i, obj := range objects {
items[i] = &item{
id: obj.Name,
container: c,
client: c.client,
hash: obj.Hash,
size: obj.Bytes,
lastModified: obj.LastModified,
}
}
marker := ""
if len(objects) == count {
marker = objects[len(objects)-1].Name
}
return items, marker, nil
} | go | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
params := &swift.ObjectsOpts{
Limit: count,
Marker: cursor,
Prefix: prefix,
}
objects, err := c.client.Objects(c.id, params)
if err != nil {
return nil, "", err
}
items := make([]stow.Item, len(objects))
for i, obj := range objects {
items[i] = &item{
id: obj.Name,
container: c,
client: c.client,
hash: obj.Hash,
size: obj.Bytes,
lastModified: obj.LastModified,
}
}
marker := ""
if len(objects) == count {
marker = objects[len(objects)-1].Name
}
return items, marker, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"Items",
"(",
"prefix",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Item",
",",
"string",
",",
"error",
")",
"{",
"params",
":=",
"&",
"swift",
".",
"ObjectsOpts",
"{",
... | // Items returns a collection of CloudStorage objects based on a matching
// prefix string and cursor information. | [
"Items",
"returns",
"a",
"collection",
"of",
"CloudStorage",
"objects",
"based",
"on",
"a",
"matching",
"prefix",
"string",
"and",
"cursor",
"information",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/container.go#L37-L65 |
8,530 | graymeta/stow | oracle/container.go | Put | func (c *container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update Item, preparing metadata")
}
_, err = c.client.ObjectPut(c.id, name, r, false, "", "", nil)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update Item")
}
err = c.client.ObjectUpdate(c.id, name, mdPrepped)
if err != nil {
return nil, errors.Wrap(err, "unable to update Item metadata")
}
item := &item{
id: name,
container: c,
client: c.client,
size: size,
// not setting metadata here, the refined version isn't available
// unless an explicit getItem() is done. Possible to write a func to facilitate
// this.
}
return item, nil
} | go | func (c *container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update Item, preparing metadata")
}
_, err = c.client.ObjectPut(c.id, name, r, false, "", "", nil)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update Item")
}
err = c.client.ObjectUpdate(c.id, name, mdPrepped)
if err != nil {
return nil, errors.Wrap(err, "unable to update Item metadata")
}
item := &item{
id: name,
container: c,
client: c.client,
size: size,
// not setting metadata here, the refined version isn't available
// unless an explicit getItem() is done. Possible to write a func to facilitate
// this.
}
return item, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"Put",
"(",
"name",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"size",
"int64",
",",
"metadata",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"stow",
".",
"Item",
",",
"error",
")",
"{",
... | // Put creates or updates a CloudStorage object within the given container. | [
"Put",
"creates",
"or",
"updates",
"a",
"CloudStorage",
"object",
"within",
"the",
"given",
"container",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/oracle/container.go#L68-L94 |
8,531 | graymeta/stow | google/item.go | prepUrl | func prepUrl(str string) (*url.URL, error) {
u, err := url.Parse(str)
if err != nil {
return nil, err
}
u.Scheme = "google"
// Discard the query string
u.RawQuery = ""
return u, nil
} | go | func prepUrl(str string) (*url.URL, error) {
u, err := url.Parse(str)
if err != nil {
return nil, err
}
u.Scheme = "google"
// Discard the query string
u.RawQuery = ""
return u, nil
} | [
"func",
"prepUrl",
"(",
"str",
"string",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",... | // prepUrl takes a MediaLink string and returns a url | [
"prepUrl",
"takes",
"a",
"MediaLink",
"string",
"and",
"returns",
"a",
"url"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/item.go#L78-L88 |
8,532 | graymeta/stow | b2/location.go | Containers | func (l *location) Containers(prefix string, cursor string, count int) ([]stow.Container, string, error) {
response, err := l.client.ListBuckets()
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, 0, len(response))
for _, cont := range response {
// api and/or library don't seem to support prefixes, so do it ourself
if strings.HasPrefix(cont.Name, prefix) {
containers = append(containers, &container{
bucket: cont,
})
}
}
return containers, "", nil
} | go | func (l *location) Containers(prefix string, cursor string, count int) ([]stow.Container, string, error) {
response, err := l.client.ListBuckets()
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, 0, len(response))
for _, cont := range response {
// api and/or library don't seem to support prefixes, so do it ourself
if strings.HasPrefix(cont.Name, prefix) {
containers = append(containers, &container{
bucket: cont,
})
}
}
return containers, "", nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"Containers",
"(",
"prefix",
"string",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Container",
",",
"string",
",",
"error",
")",
"{",
"response",
",",
"err",
":=",
"l",
"."... | // Containers lists all containers in the location | [
"Containers",
"lists",
"all",
"containers",
"in",
"the",
"location"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/location.go#L34-L51 |
8,533 | graymeta/stow | b2/location.go | Container | func (l *location) Container(id string) (stow.Container, error) {
bucket, err := l.client.Bucket(id)
if err != nil || bucket == nil {
return nil, stow.ErrNotFound
}
return &container{
bucket: bucket,
}, nil
} | go | func (l *location) Container(id string) (stow.Container, error) {
bucket, err := l.client.Bucket(id)
if err != nil || bucket == nil {
return nil, stow.ErrNotFound
}
return &container{
bucket: bucket,
}, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"Container",
"(",
"id",
"string",
")",
"(",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"bucket",
",",
"err",
":=",
"l",
".",
"client",
".",
"Bucket",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // Container returns a stow.Contaner given a container id. In this case, the 'id'
// is really the bucket name | [
"Container",
"returns",
"a",
"stow",
".",
"Contaner",
"given",
"a",
"container",
"id",
".",
"In",
"this",
"case",
"the",
"id",
"is",
"really",
"the",
"bucket",
"name"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/location.go#L55-L64 |
8,534 | graymeta/stow | b2/location.go | ItemByURL | func (l *location) ItemByURL(u *url.URL) (stow.Item, error) {
if u.Scheme != Kind {
return nil, errors.New("not valid b2 URL")
}
// b2://f001.backblaze.com/file/<container_name>/<path_to_object>
pieces := strings.SplitN(u.Path, "/", 4)
c, err := l.Container(pieces[2])
if err != nil {
return nil, err
}
filename, err := url.QueryUnescape(pieces[3])
if err != nil {
return nil, err
}
response, err := c.(*container).bucket.ListFileNames(filename, 1)
if err != nil {
return nil, stow.ErrNotFound
}
if len(response.Files) != 1 {
return nil, errors.New("unexpected number of responses from ListFileNames")
}
return c.Item(response.Files[0].ID)
} | go | func (l *location) ItemByURL(u *url.URL) (stow.Item, error) {
if u.Scheme != Kind {
return nil, errors.New("not valid b2 URL")
}
// b2://f001.backblaze.com/file/<container_name>/<path_to_object>
pieces := strings.SplitN(u.Path, "/", 4)
c, err := l.Container(pieces[2])
if err != nil {
return nil, err
}
filename, err := url.QueryUnescape(pieces[3])
if err != nil {
return nil, err
}
response, err := c.(*container).bucket.ListFileNames(filename, 1)
if err != nil {
return nil, stow.ErrNotFound
}
if len(response.Files) != 1 {
return nil, errors.New("unexpected number of responses from ListFileNames")
}
return c.Item(response.Files[0].ID)
} | [
"func",
"(",
"l",
"*",
"location",
")",
"ItemByURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"stow",
".",
"Item",
",",
"error",
")",
"{",
"if",
"u",
".",
"Scheme",
"!=",
"Kind",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
... | // ItemByURL returns a stow.Item given a b2 stow url | [
"ItemByURL",
"returns",
"a",
"stow",
".",
"Item",
"given",
"a",
"b2",
"stow",
"url"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/location.go#L67-L94 |
8,535 | graymeta/stow | b2/location.go | RemoveContainer | func (l *location) RemoveContainer(id string) error {
stowCont, err := l.Container(id)
if err != nil {
return err
}
return stowCont.(*container).bucket.Delete()
} | go | func (l *location) RemoveContainer(id string) error {
stowCont, err := l.Container(id)
if err != nil {
return err
}
return stowCont.(*container).bucket.Delete()
} | [
"func",
"(",
"l",
"*",
"location",
")",
"RemoveContainer",
"(",
"id",
"string",
")",
"error",
"{",
"stowCont",
",",
"err",
":=",
"l",
".",
"Container",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return... | // RemoveContainer removes the specified bucket. In this case, the 'id'
// is really the bucket name | [
"RemoveContainer",
"removes",
"the",
"specified",
"bucket",
".",
"In",
"this",
"case",
"the",
"id",
"is",
"really",
"the",
"bucket",
"name"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/location.go#L98-L105 |
8,536 | graymeta/stow | s3/container.go | Items | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
itemLimit := int64(count)
params := &s3.ListObjectsV2Input{
Bucket: aws.String(c.Name()),
StartAfter: &cursor,
MaxKeys: &itemLimit,
Prefix: &prefix,
}
response, err := c.client.ListObjectsV2(params)
if err != nil {
return nil, "", errors.Wrap(err, "Items, listing objects")
}
var containerItems []stow.Item
for _, object := range response.Contents {
if *object.StorageClass == "GLACIER" {
continue
}
etag := cleanEtag(*object.ETag) // Copy etag value and remove the strings.
object.ETag = &etag // Assign the value to the object field representing the item.
newItem := &item{
container: c,
client: c.client,
properties: properties{
ETag: object.ETag,
Key: object.Key,
LastModified: object.LastModified,
Owner: object.Owner,
Size: object.Size,
StorageClass: object.StorageClass,
},
}
containerItems = append(containerItems, newItem)
}
// Create a marker and determine if the list of items to retrieve is complete.
// If not, the last file is the input to the value of after which item to start
startAfter := ""
if *response.IsTruncated {
startAfter = containerItems[len(containerItems)-1].Name()
}
return containerItems, startAfter, nil
} | go | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
itemLimit := int64(count)
params := &s3.ListObjectsV2Input{
Bucket: aws.String(c.Name()),
StartAfter: &cursor,
MaxKeys: &itemLimit,
Prefix: &prefix,
}
response, err := c.client.ListObjectsV2(params)
if err != nil {
return nil, "", errors.Wrap(err, "Items, listing objects")
}
var containerItems []stow.Item
for _, object := range response.Contents {
if *object.StorageClass == "GLACIER" {
continue
}
etag := cleanEtag(*object.ETag) // Copy etag value and remove the strings.
object.ETag = &etag // Assign the value to the object field representing the item.
newItem := &item{
container: c,
client: c.client,
properties: properties{
ETag: object.ETag,
Key: object.Key,
LastModified: object.LastModified,
Owner: object.Owner,
Size: object.Size,
StorageClass: object.StorageClass,
},
}
containerItems = append(containerItems, newItem)
}
// Create a marker and determine if the list of items to retrieve is complete.
// If not, the last file is the input to the value of after which item to start
startAfter := ""
if *response.IsTruncated {
startAfter = containerItems[len(containerItems)-1].Name()
}
return containerItems, startAfter, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"Items",
"(",
"prefix",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Item",
",",
"string",
",",
"error",
")",
"{",
"itemLimit",
":=",
"int64",
"(",
"count",
")",
"\n\n",
... | // Items sends a request to retrieve a list of items that are prepended with
// the prefix argument. The 'cursor' variable facilitates pagination. | [
"Items",
"sends",
"a",
"request",
"to",
"retrieve",
"a",
"list",
"of",
"items",
"that",
"are",
"prepended",
"with",
"the",
"prefix",
"argument",
".",
"The",
"cursor",
"variable",
"facilitates",
"pagination",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/container.go#L45-L92 |
8,537 | graymeta/stow | s3/container.go | getItem | func (c *container) getItem(id string) (*item, error) {
params := &s3.HeadObjectInput{
Bucket: aws.String(c.name),
Key: aws.String(id),
}
res, err := c.client.HeadObject(params)
if err != nil {
// stow needs ErrNotFound to pass the test but amazon returns an opaque error
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "NotFound" {
return nil, stow.ErrNotFound
}
return nil, errors.Wrap(err, "getItem, getting the object")
}
etag := cleanEtag(*res.ETag) // etag string value contains quotations. Remove them.
md, err := parseMetadata(res.Metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to retrieve Item information, parsing metadata")
}
i := &item{
container: c,
client: c.client,
properties: properties{
ETag: &etag,
Key: &id,
LastModified: res.LastModified,
Owner: nil, // not returned in the response.
Size: res.ContentLength,
StorageClass: res.StorageClass,
Metadata: md,
},
}
return i, nil
} | go | func (c *container) getItem(id string) (*item, error) {
params := &s3.HeadObjectInput{
Bucket: aws.String(c.name),
Key: aws.String(id),
}
res, err := c.client.HeadObject(params)
if err != nil {
// stow needs ErrNotFound to pass the test but amazon returns an opaque error
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "NotFound" {
return nil, stow.ErrNotFound
}
return nil, errors.Wrap(err, "getItem, getting the object")
}
etag := cleanEtag(*res.ETag) // etag string value contains quotations. Remove them.
md, err := parseMetadata(res.Metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to retrieve Item information, parsing metadata")
}
i := &item{
container: c,
client: c.client,
properties: properties{
ETag: &etag,
Key: &id,
LastModified: res.LastModified,
Owner: nil, // not returned in the response.
Size: res.ContentLength,
StorageClass: res.StorageClass,
Metadata: md,
},
}
return i, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"getItem",
"(",
"id",
"string",
")",
"(",
"*",
"item",
",",
"error",
")",
"{",
"params",
":=",
"&",
"s3",
".",
"HeadObjectInput",
"{",
"Bucket",
":",
"aws",
".",
"String",
"(",
"c",
".",
"name",
")",
",",
... | // A request to retrieve a single item includes information that is more specific than
// a PUT. Instead of doing a request within the PUT, make this method available so that the
// request can be made by the field retrieval methods when necessary. This is the case for
// fields that are left out, such as the object's last modified date. This also needs to be
// done only once since the requested information is retained.
// May be simpler to just stick it in PUT and and do a request every time, please vouch
// for this if so. | [
"A",
"request",
"to",
"retrieve",
"a",
"single",
"item",
"includes",
"information",
"that",
"is",
"more",
"specific",
"than",
"a",
"PUT",
".",
"Instead",
"of",
"doing",
"a",
"request",
"within",
"the",
"PUT",
"make",
"this",
"method",
"available",
"so",
"t... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/container.go#L171-L207 |
8,538 | graymeta/stow | s3/container.go | parseMetadata | func parseMetadata(md map[string]*string) (map[string]interface{}, error) {
m := make(map[string]interface{}, len(md))
for key, value := range md {
k := strings.ToLower(key)
m[k] = *value
}
return m, nil
} | go | func parseMetadata(md map[string]*string) (map[string]interface{}, error) {
m := make(map[string]interface{}, len(md))
for key, value := range md {
k := strings.ToLower(key)
m[k] = *value
}
return m, nil
} | [
"func",
"parseMetadata",
"(",
"md",
"map",
"[",
"string",
"]",
"*",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len"... | // The first letter of a dash separated key value is capitalized, so perform a ToLower on it.
// This Key transformation of returning lowercase is consistent with other locations.. | [
"The",
"first",
"letter",
"of",
"a",
"dash",
"separated",
"key",
"value",
"is",
"capitalized",
"so",
"perform",
"a",
"ToLower",
"on",
"it",
".",
"This",
"Key",
"transformation",
"of",
"returning",
"lowercase",
"is",
"consistent",
"with",
"other",
"locations",
... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/container.go#L261-L268 |
8,539 | graymeta/stow | local/container.go | flatdirs | func flatdirs(path string) ([]os.FileInfo, error) {
var list []os.FileInfo
err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
flatname, err := filepath.Rel(path, p)
if err != nil {
return err
}
list = append(list, fileinfo{
FileInfo: info,
name: flatname,
})
return nil
})
if err != nil {
return nil, err
}
return list, nil
} | go | func flatdirs(path string) ([]os.FileInfo, error) {
var list []os.FileInfo
err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
flatname, err := filepath.Rel(path, p)
if err != nil {
return err
}
list = append(list, fileinfo{
FileInfo: info,
name: flatname,
})
return nil
})
if err != nil {
return nil, err
}
return list, nil
} | [
"func",
"flatdirs",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"var",
"list",
"[",
"]",
"os",
".",
"FileInfo",
"\n",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"path",
",",
"func",
"(",
"p",
"string"... | // flatdirs walks the entire tree returning a list of
// os.FileInfo for all items encountered. | [
"flatdirs",
"walks",
"the",
"entire",
"tree",
"returning",
"a",
"list",
"of",
"os",
".",
"FileInfo",
"for",
"all",
"items",
"encountered",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/local/container.go#L152-L175 |
8,540 | graymeta/stow | azure/multipart.go | determineChunkSize | func determineChunkSize(size int64) (int64, error) {
var chunkSize = int64(startChunkSize)
for {
parts := size / chunkSize
rem := size % chunkSize
if rem != 0 {
parts++
}
if parts <= maxParts {
break
}
if chunkSize == maxChunkSize {
return 0, errMultiPartUploadTooBig
}
chunkSize *= 2
if chunkSize > maxChunkSize {
chunkSize = maxChunkSize
}
}
return chunkSize, nil
} | go | func determineChunkSize(size int64) (int64, error) {
var chunkSize = int64(startChunkSize)
for {
parts := size / chunkSize
rem := size % chunkSize
if rem != 0 {
parts++
}
if parts <= maxParts {
break
}
if chunkSize == maxChunkSize {
return 0, errMultiPartUploadTooBig
}
chunkSize *= 2
if chunkSize > maxChunkSize {
chunkSize = maxChunkSize
}
}
return chunkSize, nil
} | [
"func",
"determineChunkSize",
"(",
"size",
"int64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"chunkSize",
"=",
"int64",
"(",
"startChunkSize",
")",
"\n\n",
"for",
"{",
"parts",
":=",
"size",
"/",
"chunkSize",
"\n",
"rem",
":=",
"size",
"%",
"c... | // determineChunkSize determines the chunk size for a multi-part upload. | [
"determineChunkSize",
"determines",
"the",
"chunk",
"size",
"for",
"a",
"multi",
"-",
"part",
"upload",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/azure/multipart.go#L30-L56 |
8,541 | graymeta/stow | azure/multipart.go | multipartUpload | func (c *container) multipartUpload(name string, r io.Reader, size int64) error {
chunkSize, err := determineChunkSize(size)
if err != nil {
return err
}
var buf = make([]byte, chunkSize)
var blocks []az.Block
var rawID uint64
blob := c.client.GetContainerReference(c.id).GetBlobReference(name)
// TODO: upload the parts in parallel
for {
n, err := r.Read(buf)
if err != nil {
if err == io.EOF {
break
}
return err
}
blockID := encodedBlockID(rawID)
chunk := buf[:n]
if err := blob.PutBlock(blockID, chunk, nil); err != nil {
return err
}
blocks = append(blocks, az.Block{
ID: blockID,
Status: az.BlockStatusLatest,
})
rawID++
}
return blob.PutBlockList(blocks, nil)
} | go | func (c *container) multipartUpload(name string, r io.Reader, size int64) error {
chunkSize, err := determineChunkSize(size)
if err != nil {
return err
}
var buf = make([]byte, chunkSize)
var blocks []az.Block
var rawID uint64
blob := c.client.GetContainerReference(c.id).GetBlobReference(name)
// TODO: upload the parts in parallel
for {
n, err := r.Read(buf)
if err != nil {
if err == io.EOF {
break
}
return err
}
blockID := encodedBlockID(rawID)
chunk := buf[:n]
if err := blob.PutBlock(blockID, chunk, nil); err != nil {
return err
}
blocks = append(blocks, az.Block{
ID: blockID,
Status: az.BlockStatusLatest,
})
rawID++
}
return blob.PutBlockList(blocks, nil)
} | [
"func",
"(",
"c",
"*",
"container",
")",
"multipartUpload",
"(",
"name",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"size",
"int64",
")",
"error",
"{",
"chunkSize",
",",
"err",
":=",
"determineChunkSize",
"(",
"size",
")",
"\n",
"if",
"err",
"!=",
... | // multipartUpload performs a multi-part upload by chunking the data, putting each chunk, then
// assembling the chunks into a blob | [
"multipartUpload",
"performs",
"a",
"multi",
"-",
"part",
"upload",
"by",
"chunking",
"the",
"data",
"putting",
"each",
"chunk",
"then",
"assembling",
"the",
"chunks",
"into",
"a",
"blob"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/azure/multipart.go#L60-L96 |
8,542 | graymeta/stow | s3/location.go | CreateContainer | func (l *location) CreateContainer(containerName string) (stow.Container, error) {
createBucketParams := &s3.CreateBucketInput{
Bucket: aws.String(containerName), // required
}
_, err := l.client.CreateBucket(createBucketParams)
if err != nil {
return nil, errors.Wrap(err, "CreateContainer, creating the bucket")
}
region, _ := l.config.Config("region")
newContainer := &container{
name: containerName,
client: l.client,
region: region,
customEndpoint: l.customEndpoint,
}
return newContainer, nil
} | go | func (l *location) CreateContainer(containerName string) (stow.Container, error) {
createBucketParams := &s3.CreateBucketInput{
Bucket: aws.String(containerName), // required
}
_, err := l.client.CreateBucket(createBucketParams)
if err != nil {
return nil, errors.Wrap(err, "CreateContainer, creating the bucket")
}
region, _ := l.config.Config("region")
newContainer := &container{
name: containerName,
client: l.client,
region: region,
customEndpoint: l.customEndpoint,
}
return newContainer, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"CreateContainer",
"(",
"containerName",
"string",
")",
"(",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"createBucketParams",
":=",
"&",
"s3",
".",
"CreateBucketInput",
"{",
"Bucket",
":",
"aws",
".",
"String"... | // CreateContainer creates a new container, in this case an S3 bucket.
// The bare minimum needed is a container name, but there are many other
// options that can be provided. | [
"CreateContainer",
"creates",
"a",
"new",
"container",
"in",
"this",
"case",
"an",
"S3",
"bucket",
".",
"The",
"bare",
"minimum",
"needed",
"is",
"a",
"container",
"name",
"but",
"there",
"are",
"many",
"other",
"options",
"that",
"can",
"be",
"provided",
... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/location.go#L27-L47 |
8,543 | graymeta/stow | s3/location.go | Containers | func (l *location) Containers(prefix, cursor string, count int) ([]stow.Container, string, error) {
// Response returns exported Owner(*s3.Owner) and Bucket(*s3.[]Bucket)
var params *s3.ListBucketsInput
bucketList, err := l.client.ListBuckets(params)
if err != nil {
return nil, "", errors.Wrap(err, "Containers, listing the buckets")
}
// Seek to the current bucket, according to cursor.
if cursor != stow.CursorStart {
ok := false
for i, b := range bucketList.Buckets {
if *b.Name == cursor {
ok = true
bucketList.Buckets = bucketList.Buckets[i:]
break
}
}
if !ok {
return nil, "", stow.ErrBadCursor
}
}
cursor = ""
// Region is pulled from stow.Config. If Region is specified, only add
// Bucket to Container list if it is located in configured Region.
region, regionSet := l.config.Config(ConfigRegion)
// Endpoint would indicate that we are using s3-compatible storage, which
// does not support s3session.GetBucketRegion().
endpoint, endpointSet := l.config.Config(ConfigEndpoint)
// Iterate through the slice of pointers to buckets
var containers []stow.Container
for _, bucket := range bucketList.Buckets {
if len(containers) == count {
cursor = *bucket.Name
break
}
if !strings.HasPrefix(*bucket.Name, prefix) {
continue
}
var err error
client := l.client
bucketRegion := region
if !endpointSet && endpoint == "" {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
bucketRegion, err = s3manager.GetBucketRegionWithClient(ctx, l.client, *bucket.Name)
cancel()
if err != nil {
return nil, "", errors.Wrapf(err, "Containers, getting bucket region for: %s", *bucket.Name)
}
if regionSet && region != "" && bucketRegion != region {
continue
}
client, _, err = newS3Client(l.config, bucketRegion)
if err != nil {
return nil, "", errors.Wrapf(err, "Containers, creating new client for region: %s", bucketRegion)
}
}
newContainer := &container{
name: *(bucket.Name),
client: client,
region: bucketRegion,
customEndpoint: l.customEndpoint,
}
containers = append(containers, newContainer)
}
return containers, cursor, nil
} | go | func (l *location) Containers(prefix, cursor string, count int) ([]stow.Container, string, error) {
// Response returns exported Owner(*s3.Owner) and Bucket(*s3.[]Bucket)
var params *s3.ListBucketsInput
bucketList, err := l.client.ListBuckets(params)
if err != nil {
return nil, "", errors.Wrap(err, "Containers, listing the buckets")
}
// Seek to the current bucket, according to cursor.
if cursor != stow.CursorStart {
ok := false
for i, b := range bucketList.Buckets {
if *b.Name == cursor {
ok = true
bucketList.Buckets = bucketList.Buckets[i:]
break
}
}
if !ok {
return nil, "", stow.ErrBadCursor
}
}
cursor = ""
// Region is pulled from stow.Config. If Region is specified, only add
// Bucket to Container list if it is located in configured Region.
region, regionSet := l.config.Config(ConfigRegion)
// Endpoint would indicate that we are using s3-compatible storage, which
// does not support s3session.GetBucketRegion().
endpoint, endpointSet := l.config.Config(ConfigEndpoint)
// Iterate through the slice of pointers to buckets
var containers []stow.Container
for _, bucket := range bucketList.Buckets {
if len(containers) == count {
cursor = *bucket.Name
break
}
if !strings.HasPrefix(*bucket.Name, prefix) {
continue
}
var err error
client := l.client
bucketRegion := region
if !endpointSet && endpoint == "" {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
bucketRegion, err = s3manager.GetBucketRegionWithClient(ctx, l.client, *bucket.Name)
cancel()
if err != nil {
return nil, "", errors.Wrapf(err, "Containers, getting bucket region for: %s", *bucket.Name)
}
if regionSet && region != "" && bucketRegion != region {
continue
}
client, _, err = newS3Client(l.config, bucketRegion)
if err != nil {
return nil, "", errors.Wrapf(err, "Containers, creating new client for region: %s", bucketRegion)
}
}
newContainer := &container{
name: *(bucket.Name),
client: client,
region: bucketRegion,
customEndpoint: l.customEndpoint,
}
containers = append(containers, newContainer)
}
return containers, cursor, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"Containers",
"(",
"prefix",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Container",
",",
"string",
",",
"error",
")",
"{",
"// Response returns exported Owner(*s3.Owner) and Bucket(*s... | // Containers returns a slice of the Container interface, a cursor, and an error.
// This doesn't seem to exist yet in the API without doing a ton of manual work.
// Get the list of buckets, query every single one to retrieve region info, and finally
// return the list of containers that have a matching region against the client. It's not
// possible to manipulate a container within a region that doesn't match the clients'.
// This is because AWS user credentials can be tied to regions. One solution would be
// to start a new client for every single container where the region matches, this would
// also check the credentials on every new instance... Tabled for later. | [
"Containers",
"returns",
"a",
"slice",
"of",
"the",
"Container",
"interface",
"a",
"cursor",
"and",
"an",
"error",
".",
"This",
"doesn",
"t",
"seem",
"to",
"exist",
"yet",
"in",
"the",
"API",
"without",
"doing",
"a",
"ton",
"of",
"manual",
"work",
".",
... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/s3/location.go#L57-L132 |
8,544 | graymeta/stow | walk.go | Walk | func Walk(container Container, prefix string, pageSize int, fn WalkFunc) error {
var (
err error
items []Item
cursor = CursorStart
)
for {
items, cursor, err = container.Items(prefix, cursor, pageSize)
if err != nil {
err = fn(nil, err)
if err != nil {
return err
}
}
for _, item := range items {
err = fn(item, nil)
if err != nil {
return err
}
}
if IsCursorEnd(cursor) {
break
}
}
return nil
} | go | func Walk(container Container, prefix string, pageSize int, fn WalkFunc) error {
var (
err error
items []Item
cursor = CursorStart
)
for {
items, cursor, err = container.Items(prefix, cursor, pageSize)
if err != nil {
err = fn(nil, err)
if err != nil {
return err
}
}
for _, item := range items {
err = fn(item, nil)
if err != nil {
return err
}
}
if IsCursorEnd(cursor) {
break
}
}
return nil
} | [
"func",
"Walk",
"(",
"container",
"Container",
",",
"prefix",
"string",
",",
"pageSize",
"int",
",",
"fn",
"WalkFunc",
")",
"error",
"{",
"var",
"(",
"err",
"error",
"\n",
"items",
"[",
"]",
"Item",
"\n",
"cursor",
"=",
"CursorStart",
"\n",
")",
"\n",
... | // Walk walks all Items in the Container.
// Returns the first error returned by the WalkFunc or
// nil if no errors were returned.
// The pageSize is the number of Items to get per request. | [
"Walk",
"walks",
"all",
"Items",
"in",
"the",
"Container",
".",
"Returns",
"the",
"first",
"error",
"returned",
"by",
"the",
"WalkFunc",
"or",
"nil",
"if",
"no",
"errors",
"were",
"returned",
".",
"The",
"pageSize",
"is",
"the",
"number",
"of",
"Items",
... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/walk.go#L17-L42 |
8,545 | graymeta/stow | walk.go | WalkContainers | func WalkContainers(location Location, prefix string, pageSize int, fn WalkContainersFunc) error {
var (
err error
containers []Container
cursor = CursorStart
)
for {
containers, cursor, err = location.Containers(prefix, cursor, pageSize)
if err != nil {
err = fn(nil, err)
if err != nil {
return err
}
}
for _, container := range containers {
err = fn(container, nil)
if err != nil {
return err
}
}
if IsCursorEnd(cursor) {
break
}
}
return nil
} | go | func WalkContainers(location Location, prefix string, pageSize int, fn WalkContainersFunc) error {
var (
err error
containers []Container
cursor = CursorStart
)
for {
containers, cursor, err = location.Containers(prefix, cursor, pageSize)
if err != nil {
err = fn(nil, err)
if err != nil {
return err
}
}
for _, container := range containers {
err = fn(container, nil)
if err != nil {
return err
}
}
if IsCursorEnd(cursor) {
break
}
}
return nil
} | [
"func",
"WalkContainers",
"(",
"location",
"Location",
",",
"prefix",
"string",
",",
"pageSize",
"int",
",",
"fn",
"WalkContainersFunc",
")",
"error",
"{",
"var",
"(",
"err",
"error",
"\n",
"containers",
"[",
"]",
"Container",
"\n",
"cursor",
"=",
"CursorSta... | // WalkContainers walks all Containers in the Location.
// Returns the first error returned by the WalkContainersFunc or
// nil if no errors were returned.
// The pageSize is the number of Containers to get per request. | [
"WalkContainers",
"walks",
"all",
"Containers",
"in",
"the",
"Location",
".",
"Returns",
"the",
"first",
"error",
"returned",
"by",
"the",
"WalkContainersFunc",
"or",
"nil",
"if",
"no",
"errors",
"were",
"returned",
".",
"The",
"pageSize",
"is",
"the",
"number... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/walk.go#L56-L81 |
8,546 | graymeta/stow | google/container.go | Item | func (c *Container) Item(id string) (stow.Item, error) {
res, err := c.client.Objects.Get(c.name, id).Do()
if err != nil {
return nil, stow.ErrNotFound
}
t, err := time.Parse(time.RFC3339, res.Updated)
if err != nil {
return nil, err
}
u, err := prepUrl(res.MediaLink)
if err != nil {
return nil, err
}
mdParsed, err := parseMetadata(res.Metadata)
if err != nil {
return nil, err
}
i := &Item{
name: id,
container: c,
client: c.client,
size: int64(res.Size),
etag: res.Etag,
hash: res.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: res,
}
return i, nil
} | go | func (c *Container) Item(id string) (stow.Item, error) {
res, err := c.client.Objects.Get(c.name, id).Do()
if err != nil {
return nil, stow.ErrNotFound
}
t, err := time.Parse(time.RFC3339, res.Updated)
if err != nil {
return nil, err
}
u, err := prepUrl(res.MediaLink)
if err != nil {
return nil, err
}
mdParsed, err := parseMetadata(res.Metadata)
if err != nil {
return nil, err
}
i := &Item{
name: id,
container: c,
client: c.client,
size: int64(res.Size),
etag: res.Etag,
hash: res.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: res,
}
return i, nil
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Item",
"(",
"id",
"string",
")",
"(",
"stow",
".",
"Item",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"c",
".",
"client",
".",
"Objects",
".",
"Get",
"(",
"c",
".",
"name",
",",
"id",
")",
".",
... | // Item returns a stow.Item instance of a container based on the
// name of the container | [
"Item",
"returns",
"a",
"stow",
".",
"Item",
"instance",
"of",
"a",
"container",
"based",
"on",
"the",
"name",
"of",
"the",
"container"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/container.go#L36-L71 |
8,547 | graymeta/stow | google/container.go | Items | func (c *Container) Items(prefix string, cursor string, count int) ([]stow.Item, string, error) {
// List all objects in a bucket using pagination
call := c.client.Objects.List(c.name).MaxResults(int64(count))
if prefix != "" {
call.Prefix(prefix)
}
if cursor != "" {
call = call.PageToken(cursor)
}
res, err := call.Do()
if err != nil {
return nil, "", err
}
containerItems := make([]stow.Item, len(res.Items))
for i, o := range res.Items {
t, err := time.Parse(time.RFC3339, o.Updated)
if err != nil {
return nil, "", err
}
u, err := prepUrl(o.MediaLink)
if err != nil {
return nil, "", err
}
mdParsed, err := parseMetadata(o.Metadata)
if err != nil {
return nil, "", err
}
containerItems[i] = &Item{
name: o.Name,
container: c,
client: c.client,
size: int64(o.Size),
etag: o.Etag,
hash: o.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: o,
}
}
return containerItems, res.NextPageToken, nil
} | go | func (c *Container) Items(prefix string, cursor string, count int) ([]stow.Item, string, error) {
// List all objects in a bucket using pagination
call := c.client.Objects.List(c.name).MaxResults(int64(count))
if prefix != "" {
call.Prefix(prefix)
}
if cursor != "" {
call = call.PageToken(cursor)
}
res, err := call.Do()
if err != nil {
return nil, "", err
}
containerItems := make([]stow.Item, len(res.Items))
for i, o := range res.Items {
t, err := time.Parse(time.RFC3339, o.Updated)
if err != nil {
return nil, "", err
}
u, err := prepUrl(o.MediaLink)
if err != nil {
return nil, "", err
}
mdParsed, err := parseMetadata(o.Metadata)
if err != nil {
return nil, "", err
}
containerItems[i] = &Item{
name: o.Name,
container: c,
client: c.client,
size: int64(o.Size),
etag: o.Etag,
hash: o.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: o,
}
}
return containerItems, res.NextPageToken, nil
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Items",
"(",
"prefix",
"string",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Item",
",",
"string",
",",
"error",
")",
"{",
"// List all objects in a bucket using pagination",
"ca... | // Items retrieves a list of items that are prepended with
// the prefix argument. The 'cursor' variable facilitates pagination. | [
"Items",
"retrieves",
"a",
"list",
"of",
"items",
"that",
"are",
"prepended",
"with",
"the",
"prefix",
"argument",
".",
"The",
"cursor",
"variable",
"facilitates",
"pagination",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/container.go#L75-L124 |
8,548 | graymeta/stow | google/container.go | Put | func (c *Container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, err
}
object := &storage.Object{
Name: name,
Metadata: mdPrepped,
}
res, err := c.client.Objects.Insert(c.name, object).Media(r).Do()
if err != nil {
return nil, err
}
t, err := time.Parse(time.RFC3339, res.Updated)
if err != nil {
return nil, err
}
u, err := prepUrl(res.MediaLink)
if err != nil {
return nil, err
}
mdParsed, err := parseMetadata(res.Metadata)
if err != nil {
return nil, err
}
newItem := &Item{
name: name,
container: c,
client: c.client,
size: size,
etag: res.Etag,
hash: res.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: res,
}
return newItem, nil
} | go | func (c *Container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, err
}
object := &storage.Object{
Name: name,
Metadata: mdPrepped,
}
res, err := c.client.Objects.Insert(c.name, object).Media(r).Do()
if err != nil {
return nil, err
}
t, err := time.Parse(time.RFC3339, res.Updated)
if err != nil {
return nil, err
}
u, err := prepUrl(res.MediaLink)
if err != nil {
return nil, err
}
mdParsed, err := parseMetadata(res.Metadata)
if err != nil {
return nil, err
}
newItem := &Item{
name: name,
container: c,
client: c.client,
size: size,
etag: res.Etag,
hash: res.Md5Hash,
lastModified: t,
url: u,
metadata: mdParsed,
object: res,
}
return newItem, nil
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Put",
"(",
"name",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"size",
"int64",
",",
"metadata",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"stow",
".",
"Item",
",",
"error",
")",
"{",
... | // Put sends a request to upload content to the container. The arguments
// received are the name of the item, a reader representing the
// content, and the size of the file. | [
"Put",
"sends",
"a",
"request",
"to",
"upload",
"content",
"to",
"the",
"container",
".",
"The",
"arguments",
"received",
"are",
"the",
"name",
"of",
"the",
"item",
"a",
"reader",
"representing",
"the",
"content",
"and",
"the",
"size",
"of",
"the",
"file",... | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/container.go#L133-L177 |
8,549 | graymeta/stow | b2/container.go | Items | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
items := make([]stow.Item, 0, count)
for {
response, err := c.bucket.ListFileNames(cursor, count)
if err != nil {
return nil, "", err
}
for _, obj := range response.Files {
if prefix != stow.NoPrefix && !strings.HasPrefix(obj.Name, prefix) {
continue
}
items = append(items, &item{
id: obj.ID,
name: obj.Name,
size: int64(obj.Size),
lastModified: time.Unix(obj.UploadTimestamp/1000, 0),
bucket: c.bucket,
})
if len(items) == count {
break
}
}
cursor = response.NextFileName
if prefix == "" || cursor == "" {
return items, cursor, nil
}
if len(items) == count {
break
}
if !strings.HasPrefix(cursor, prefix) {
return items, "", nil
}
}
if cursor != "" && cursor != items[len(items)-1].Name() {
// append a space because that's a funny quirk of backblaze's implementation
cursor = items[len(items)-1].Name() + " "
}
return items, cursor, nil
} | go | func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) {
items := make([]stow.Item, 0, count)
for {
response, err := c.bucket.ListFileNames(cursor, count)
if err != nil {
return nil, "", err
}
for _, obj := range response.Files {
if prefix != stow.NoPrefix && !strings.HasPrefix(obj.Name, prefix) {
continue
}
items = append(items, &item{
id: obj.ID,
name: obj.Name,
size: int64(obj.Size),
lastModified: time.Unix(obj.UploadTimestamp/1000, 0),
bucket: c.bucket,
})
if len(items) == count {
break
}
}
cursor = response.NextFileName
if prefix == "" || cursor == "" {
return items, cursor, nil
}
if len(items) == count {
break
}
if !strings.HasPrefix(cursor, prefix) {
return items, "", nil
}
}
if cursor != "" && cursor != items[len(items)-1].Name() {
// append a space because that's a funny quirk of backblaze's implementation
cursor = items[len(items)-1].Name() + " "
}
return items, cursor, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"Items",
"(",
"prefix",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Item",
",",
"string",
",",
"error",
")",
"{",
"items",
":=",
"make",
"(",
"[",
"]",
"stow",
".",
"I... | // Items retreives a list of items from b2. Since the b2 ListFileNames operation
// does not natively support a prefix, we fake it ourselves | [
"Items",
"retreives",
"a",
"list",
"of",
"items",
"from",
"b2",
".",
"Since",
"the",
"b2",
"ListFileNames",
"operation",
"does",
"not",
"natively",
"support",
"a",
"prefix",
"we",
"fake",
"it",
"ourselves"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/container.go#L39-L84 |
8,550 | graymeta/stow | b2/container.go | Put | func (c *container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
// Convert map[string]interface{} to map[string]string
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update item, preparing metadata")
}
file, err := c.bucket.UploadFile(name, mdPrepped, r)
if err != nil {
return nil, err
}
return &item{
id: file.ID,
name: file.Name,
size: file.ContentLength,
bucket: c.bucket,
}, nil
} | go | func (c *container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
// Convert map[string]interface{} to map[string]string
mdPrepped, err := prepMetadata(metadata)
if err != nil {
return nil, errors.Wrap(err, "unable to create or update item, preparing metadata")
}
file, err := c.bucket.UploadFile(name, mdPrepped, r)
if err != nil {
return nil, err
}
return &item{
id: file.ID,
name: file.Name,
size: file.ContentLength,
bucket: c.bucket,
}, nil
} | [
"func",
"(",
"c",
"*",
"container",
")",
"Put",
"(",
"name",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"size",
"int64",
",",
"metadata",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"stow",
".",
"Item",
",",
"error",
")",
"{",
... | // Put uploads a file | [
"Put",
"uploads",
"a",
"file"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/container.go#L87-L105 |
8,551 | graymeta/stow | b2/container.go | RemoveItem | func (c *container) RemoveItem(id string) error {
item, err := c.getItem(id)
if err != nil {
return err
}
// files can have multiple versions in backblaze. You have to delete
// files one version at a time.
for {
response, err := item.bucket.ListFileNames(item.Name(), 1)
if err != nil {
return err
}
var fileStatus *backblaze.FileStatus
for i := range response.Files {
if response.Files[i].Name == item.Name() {
fileStatus = &response.Files[i]
break
}
}
if fileStatus == nil {
// we've deleted all versions of the file
return nil
}
if _, err := c.bucket.DeleteFileVersion(item.name, response.Files[0].ID); err != nil {
return err
}
}
} | go | func (c *container) RemoveItem(id string) error {
item, err := c.getItem(id)
if err != nil {
return err
}
// files can have multiple versions in backblaze. You have to delete
// files one version at a time.
for {
response, err := item.bucket.ListFileNames(item.Name(), 1)
if err != nil {
return err
}
var fileStatus *backblaze.FileStatus
for i := range response.Files {
if response.Files[i].Name == item.Name() {
fileStatus = &response.Files[i]
break
}
}
if fileStatus == nil {
// we've deleted all versions of the file
return nil
}
if _, err := c.bucket.DeleteFileVersion(item.name, response.Files[0].ID); err != nil {
return err
}
}
} | [
"func",
"(",
"c",
"*",
"container",
")",
"RemoveItem",
"(",
"id",
"string",
")",
"error",
"{",
"item",
",",
"err",
":=",
"c",
".",
"getItem",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// files can hav... | // RemoveItem identifies the file by it's ID, then removes all versions of that file | [
"RemoveItem",
"identifies",
"the",
"file",
"by",
"it",
"s",
"ID",
"then",
"removes",
"all",
"versions",
"of",
"that",
"file"
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/b2/container.go#L108-L138 |
8,552 | graymeta/stow | local/location.go | filesToContainers | func (l *location) filesToContainers(root string, files ...string) ([]stow.Container, error) {
cs := make([]stow.Container, 0, len(files))
for _, f := range files {
info, err := os.Stat(f)
if err != nil {
return nil, err
}
if !info.IsDir() {
continue
}
absroot, err := filepath.Abs(root)
if err != nil {
return nil, err
}
path, err := filepath.Abs(f)
if err != nil {
return nil, err
}
name, err := filepath.Rel(absroot, path)
if err != nil {
return nil, err
}
cs = append(cs, &container{
name: name,
path: path,
})
}
return cs, nil
} | go | func (l *location) filesToContainers(root string, files ...string) ([]stow.Container, error) {
cs := make([]stow.Container, 0, len(files))
for _, f := range files {
info, err := os.Stat(f)
if err != nil {
return nil, err
}
if !info.IsDir() {
continue
}
absroot, err := filepath.Abs(root)
if err != nil {
return nil, err
}
path, err := filepath.Abs(f)
if err != nil {
return nil, err
}
name, err := filepath.Rel(absroot, path)
if err != nil {
return nil, err
}
cs = append(cs, &container{
name: name,
path: path,
})
}
return cs, nil
} | [
"func",
"(",
"l",
"*",
"location",
")",
"filesToContainers",
"(",
"root",
"string",
",",
"files",
"...",
"string",
")",
"(",
"[",
"]",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"cs",
":=",
"make",
"(",
"[",
"]",
"stow",
".",
"Container",
",... | // filesToContainers takes a list of files and turns it into a
// stow.ContainerList. | [
"filesToContainers",
"takes",
"a",
"list",
"of",
"files",
"and",
"turns",
"it",
"into",
"a",
"stow",
".",
"ContainerList",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/local/location.go#L131-L159 |
8,553 | graymeta/stow | google/location.go | CreateContainer | func (l *Location) CreateContainer(containerName string) (stow.Container, error) {
projId, _ := l.config.Config(ConfigProjectId)
// Create a bucket.
_, err := l.client.Buckets.Insert(projId, &storage.Bucket{Name: containerName}).Do()
//res, err := l.client.Buckets.Insert(projId, &storage.Bucket{Name: containerName}).Do()
if err != nil {
return nil, err
}
newContainer := &Container{
name: containerName,
client: l.client,
}
return newContainer, nil
} | go | func (l *Location) CreateContainer(containerName string) (stow.Container, error) {
projId, _ := l.config.Config(ConfigProjectId)
// Create a bucket.
_, err := l.client.Buckets.Insert(projId, &storage.Bucket{Name: containerName}).Do()
//res, err := l.client.Buckets.Insert(projId, &storage.Bucket{Name: containerName}).Do()
if err != nil {
return nil, err
}
newContainer := &Container{
name: containerName,
client: l.client,
}
return newContainer, nil
} | [
"func",
"(",
"l",
"*",
"Location",
")",
"CreateContainer",
"(",
"containerName",
"string",
")",
"(",
"stow",
".",
"Container",
",",
"error",
")",
"{",
"projId",
",",
"_",
":=",
"l",
".",
"config",
".",
"Config",
"(",
"ConfigProjectId",
")",
"\n",
"// C... | // CreateContainer creates a new container, in this case a bucket. | [
"CreateContainer",
"creates",
"a",
"new",
"container",
"in",
"this",
"case",
"a",
"bucket",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/location.go#L29-L45 |
8,554 | graymeta/stow | google/location.go | Containers | func (l *Location) Containers(prefix string, cursor string, count int) ([]stow.Container, string, error) {
projId, _ := l.config.Config(ConfigProjectId)
// List all objects in a bucket using pagination
call := l.client.Buckets.List(projId).MaxResults(int64(count))
if prefix != "" {
call.Prefix(prefix)
}
if cursor != "" {
call = call.PageToken(cursor)
}
res, err := call.Do()
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, len(res.Items))
for i, o := range res.Items {
containers[i] = &Container{
name: o.Name,
client: l.client,
}
}
return containers, res.NextPageToken, nil
} | go | func (l *Location) Containers(prefix string, cursor string, count int) ([]stow.Container, string, error) {
projId, _ := l.config.Config(ConfigProjectId)
// List all objects in a bucket using pagination
call := l.client.Buckets.List(projId).MaxResults(int64(count))
if prefix != "" {
call.Prefix(prefix)
}
if cursor != "" {
call = call.PageToken(cursor)
}
res, err := call.Do()
if err != nil {
return nil, "", err
}
containers := make([]stow.Container, len(res.Items))
for i, o := range res.Items {
containers[i] = &Container{
name: o.Name,
client: l.client,
}
}
return containers, res.NextPageToken, nil
} | [
"func",
"(",
"l",
"*",
"Location",
")",
"Containers",
"(",
"prefix",
"string",
",",
"cursor",
"string",
",",
"count",
"int",
")",
"(",
"[",
"]",
"stow",
".",
"Container",
",",
"string",
",",
"error",
")",
"{",
"projId",
",",
"_",
":=",
"l",
".",
... | // Containers returns a slice of the Container interface, a cursor, and an error. | [
"Containers",
"returns",
"a",
"slice",
"of",
"the",
"Container",
"interface",
"a",
"cursor",
"and",
"an",
"error",
"."
] | 00c3b5928f2a541754b130a072c98a7389609686 | https://github.com/graymeta/stow/blob/00c3b5928f2a541754b130a072c98a7389609686/google/location.go#L48-L77 |
8,555 | h2non/gock | store.go | Register | func Register(mock Mock) {
if Exists(mock) {
return
}
// Make ops thread safe
mutex.Lock()
defer mutex.Unlock()
// Expose mock in request/response for delegation
mock.Request().Mock = mock
mock.Response().Mock = mock
// Registers the mock in the global store
mocks = append(mocks, mock)
} | go | func Register(mock Mock) {
if Exists(mock) {
return
}
// Make ops thread safe
mutex.Lock()
defer mutex.Unlock()
// Expose mock in request/response for delegation
mock.Request().Mock = mock
mock.Response().Mock = mock
// Registers the mock in the global store
mocks = append(mocks, mock)
} | [
"func",
"Register",
"(",
"mock",
"Mock",
")",
"{",
"if",
"Exists",
"(",
"mock",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// Make ops thread safe",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Expose mock in ... | // Register registers a new mock in the current mocks stack. | [
"Register",
"registers",
"a",
"new",
"mock",
"in",
"the",
"current",
"mocks",
"stack",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/store.go#L14-L29 |
8,556 | h2non/gock | store.go | Exists | func Exists(m Mock) bool {
storeMutex.RLock()
defer storeMutex.RUnlock()
for _, mock := range mocks {
if mock == m {
return true
}
}
return false
} | go | func Exists(m Mock) bool {
storeMutex.RLock()
defer storeMutex.RUnlock()
for _, mock := range mocks {
if mock == m {
return true
}
}
return false
} | [
"func",
"Exists",
"(",
"m",
"Mock",
")",
"bool",
"{",
"storeMutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"storeMutex",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"mock",
":=",
"range",
"mocks",
"{",
"if",
"mock",
"==",
"m",
"{",
"return",
... | // Exists checks if the given Mock is already registered. | [
"Exists",
"checks",
"if",
"the",
"given",
"Mock",
"is",
"already",
"registered",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/store.go#L39-L48 |
8,557 | h2non/gock | store.go | Remove | func Remove(m Mock) {
for i, mock := range mocks {
if mock == m {
storeMutex.Lock()
mocks = append(mocks[:i], mocks[i+1:]...)
storeMutex.Unlock()
}
}
} | go | func Remove(m Mock) {
for i, mock := range mocks {
if mock == m {
storeMutex.Lock()
mocks = append(mocks[:i], mocks[i+1:]...)
storeMutex.Unlock()
}
}
} | [
"func",
"Remove",
"(",
"m",
"Mock",
")",
"{",
"for",
"i",
",",
"mock",
":=",
"range",
"mocks",
"{",
"if",
"mock",
"==",
"m",
"{",
"storeMutex",
".",
"Lock",
"(",
")",
"\n",
"mocks",
"=",
"append",
"(",
"mocks",
"[",
":",
"i",
"]",
",",
"mocks",... | // Remove removes a registered mock by reference. | [
"Remove",
"removes",
"a",
"registered",
"mock",
"by",
"reference",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/store.go#L51-L59 |
8,558 | h2non/gock | store.go | Clean | func Clean() {
storeMutex.Lock()
defer storeMutex.Unlock()
buf := []Mock{}
for _, mock := range mocks {
if mock.Done() {
continue
}
buf = append(buf, mock)
}
mocks = buf
} | go | func Clean() {
storeMutex.Lock()
defer storeMutex.Unlock()
buf := []Mock{}
for _, mock := range mocks {
if mock.Done() {
continue
}
buf = append(buf, mock)
}
mocks = buf
} | [
"func",
"Clean",
"(",
")",
"{",
"storeMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"storeMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"buf",
":=",
"[",
"]",
"Mock",
"{",
"}",
"\n",
"for",
"_",
",",
"mock",
":=",
"range",
"mocks",
"{",
"if",
"mock",
... | // Clean cleans the mocks store removing disabled or obsolete mocks. | [
"Clean",
"cleans",
"the",
"mocks",
"store",
"removing",
"disabled",
"or",
"obsolete",
"mocks",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/store.go#L87-L100 |
8,559 | h2non/gock | matcher.go | Add | func (m *MockMatcher) Add(fn MatchFunc) {
m.Matchers = append(m.Matchers, fn)
} | go | func (m *MockMatcher) Add(fn MatchFunc) {
m.Matchers = append(m.Matchers, fn)
} | [
"func",
"(",
"m",
"*",
"MockMatcher",
")",
"Add",
"(",
"fn",
"MatchFunc",
")",
"{",
"m",
".",
"Matchers",
"=",
"append",
"(",
"m",
".",
"Matchers",
",",
"fn",
")",
"\n",
"}"
] | // Add adds a new function matcher. | [
"Add",
"adds",
"a",
"new",
"function",
"matcher",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matcher.go#L76-L78 |
8,560 | h2non/gock | matcher.go | Match | func (m *MockMatcher) Match(req *http.Request, ereq *Request) (bool, error) {
for _, matcher := range m.Matchers {
matches, err := matcher(req, ereq)
if err != nil {
return false, err
}
if !matches {
return false, nil
}
}
return true, nil
} | go | func (m *MockMatcher) Match(req *http.Request, ereq *Request) (bool, error) {
for _, matcher := range m.Matchers {
matches, err := matcher(req, ereq)
if err != nil {
return false, err
}
if !matches {
return false, nil
}
}
return true, nil
} | [
"func",
"(",
"m",
"*",
"MockMatcher",
")",
"Match",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"_",
",",
"matcher",
":=",
"range",
"m",
".",
"Matchers",
"{",
"matches",
"... | // Match matches the given http.Request with a mock request
// returning true in case that the request matches, otherwise false. | [
"Match",
"matches",
"the",
"given",
"http",
".",
"Request",
"with",
"a",
"mock",
"request",
"returning",
"true",
"in",
"case",
"that",
"the",
"request",
"matches",
"otherwise",
"false",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matcher.go#L92-L103 |
8,561 | h2non/gock | matcher.go | MatchMock | func MatchMock(req *http.Request) (Mock, error) {
for _, mock := range GetAll() {
matches, err := mock.Match(req)
if err != nil {
return nil, err
}
if matches {
return mock, nil
}
}
return nil, nil
} | go | func MatchMock(req *http.Request) (Mock, error) {
for _, mock := range GetAll() {
matches, err := mock.Match(req)
if err != nil {
return nil, err
}
if matches {
return mock, nil
}
}
return nil, nil
} | [
"func",
"MatchMock",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"Mock",
",",
"error",
")",
"{",
"for",
"_",
",",
"mock",
":=",
"range",
"GetAll",
"(",
")",
"{",
"matches",
",",
"err",
":=",
"mock",
".",
"Match",
"(",
"req",
")",
"\n",
"... | // MatchMock is a helper function that matches the given http.Request
// in the list of registered mocks, returning it if matches or error if it fails. | [
"MatchMock",
"is",
"a",
"helper",
"function",
"that",
"matches",
"the",
"given",
"http",
".",
"Request",
"in",
"the",
"list",
"of",
"registered",
"mocks",
"returning",
"it",
"if",
"matches",
"or",
"error",
"if",
"it",
"fails",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matcher.go#L107-L118 |
8,562 | h2non/gock | request.go | NewRequest | func NewRequest() *Request {
return &Request{
Counter: 1,
URLStruct: &url.URL{},
Header: make(http.Header),
PathParams: make(map[string]string),
}
} | go | func NewRequest() *Request {
return &Request{
Counter: 1,
URLStruct: &url.URL{},
Header: make(http.Header),
PathParams: make(map[string]string),
}
} | [
"func",
"NewRequest",
"(",
")",
"*",
"Request",
"{",
"return",
"&",
"Request",
"{",
"Counter",
":",
"1",
",",
"URLStruct",
":",
"&",
"url",
".",
"URL",
"{",
"}",
",",
"Header",
":",
"make",
"(",
"http",
".",
"Header",
")",
",",
"PathParams",
":",
... | // NewRequest creates a new Request instance. | [
"NewRequest",
"creates",
"a",
"new",
"Request",
"instance",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L65-L72 |
8,563 | h2non/gock | request.go | URL | func (r *Request) URL(uri string) *Request {
r.URLStruct, r.Error = url.Parse(uri)
return r
} | go | func (r *Request) URL(uri string) *Request {
r.URLStruct, r.Error = url.Parse(uri)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"URL",
"(",
"uri",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"URLStruct",
",",
"r",
".",
"Error",
"=",
"url",
".",
"Parse",
"(",
"uri",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // URL defines the mock URL to match. | [
"URL",
"defines",
"the",
"mock",
"URL",
"to",
"match",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L75-L78 |
8,564 | h2non/gock | request.go | SetURL | func (r *Request) SetURL(u *url.URL) *Request {
r.URLStruct = u
return r
} | go | func (r *Request) SetURL(u *url.URL) *Request {
r.URLStruct = u
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"SetURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"*",
"Request",
"{",
"r",
".",
"URLStruct",
"=",
"u",
"\n",
"return",
"r",
"\n",
"}"
] | // SetURL defines the url.URL struct to be used for matching. | [
"SetURL",
"defines",
"the",
"url",
".",
"URL",
"struct",
"to",
"be",
"used",
"for",
"matching",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L81-L84 |
8,565 | h2non/gock | request.go | method | func (r *Request) method(method, path string) *Request {
if path != "/" {
r.URLStruct.Path = path
}
r.Method = strings.ToUpper(method)
return r
} | go | func (r *Request) method(method, path string) *Request {
if path != "/" {
r.URLStruct.Path = path
}
r.Method = strings.ToUpper(method)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"method",
"(",
"method",
",",
"path",
"string",
")",
"*",
"Request",
"{",
"if",
"path",
"!=",
"\"",
"\"",
"{",
"r",
".",
"URLStruct",
".",
"Path",
"=",
"path",
"\n",
"}",
"\n",
"r",
".",
"Method",
"=",
"st... | // method is a DRY shortcut used to declare the expected HTTP method and URL path. | [
"method",
"is",
"a",
"DRY",
"shortcut",
"used",
"to",
"declare",
"the",
"expected",
"HTTP",
"method",
"and",
"URL",
"path",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L123-L129 |
8,566 | h2non/gock | request.go | BodyString | func (r *Request) BodyString(body string) *Request {
r.BodyBuffer = []byte(body)
return r
} | go | func (r *Request) BodyString(body string) *Request {
r.BodyBuffer = []byte(body)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"BodyString",
"(",
"body",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"BodyBuffer",
"=",
"[",
"]",
"byte",
"(",
"body",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // BodyString defines the body to match based on a given string. | [
"BodyString",
"defines",
"the",
"body",
"to",
"match",
"based",
"on",
"a",
"given",
"string",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L138-L141 |
8,567 | h2non/gock | request.go | File | func (r *Request) File(path string) *Request {
r.BodyBuffer, r.Error = ioutil.ReadFile(path)
return r
} | go | func (r *Request) File(path string) *Request {
r.BodyBuffer, r.Error = ioutil.ReadFile(path)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"File",
"(",
"path",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"BodyBuffer",
",",
"r",
".",
"Error",
"=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // File defines the body to match based on the given file path string. | [
"File",
"defines",
"the",
"body",
"to",
"match",
"based",
"on",
"the",
"given",
"file",
"path",
"string",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L144-L147 |
8,568 | h2non/gock | request.go | Compression | func (r *Request) Compression(scheme string) *Request {
r.Header.Set("Content-Encoding", scheme)
r.CompressionScheme = scheme
return r
} | go | func (r *Request) Compression(scheme string) *Request {
r.Header.Set("Content-Encoding", scheme)
r.CompressionScheme = scheme
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Compression",
"(",
"scheme",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"scheme",
")",
"\n",
"r",
".",
"CompressionScheme",
"=",
"scheme",
"\n",
"return",
"r",
"... | // Compression defines the request compression scheme, and enables automatic body decompression.
// Supports only the "gzip" scheme so far. | [
"Compression",
"defines",
"the",
"request",
"compression",
"scheme",
"and",
"enables",
"automatic",
"body",
"decompression",
".",
"Supports",
"only",
"the",
"gzip",
"scheme",
"so",
"far",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L151-L155 |
8,569 | h2non/gock | request.go | JSON | func (r *Request) JSON(data interface{}) *Request {
if r.Header.Get("Content-Type") == "" {
r.Header.Set("Content-Type", "application/json")
}
r.BodyBuffer, r.Error = readAndDecode(data, "json")
return r
} | go | func (r *Request) JSON(data interface{}) *Request {
if r.Header.Get("Content-Type") == "" {
r.Header.Set("Content-Type", "application/json")
}
r.BodyBuffer, r.Error = readAndDecode(data, "json")
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"JSON",
"(",
"data",
"interface",
"{",
"}",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
... | // JSON defines the JSON body to match based on a given structure. | [
"JSON",
"defines",
"the",
"JSON",
"body",
"to",
"match",
"based",
"on",
"a",
"given",
"structure",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L158-L164 |
8,570 | h2non/gock | request.go | BasicAuth | func (r *Request) BasicAuth(username, password string) *Request {
r.Header.Set("Authorization", "Basic "+basicAuth(username, password))
return r
} | go | func (r *Request) BasicAuth(username, password string) *Request {
r.Header.Set("Authorization", "Basic "+basicAuth(username, password))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"BasicAuth",
"(",
"username",
",",
"password",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"basicAuth",
"(",
"username",
",",
"password",
")",
")"... | // BasicAuth defines a username and password for HTTP Basic Authentication | [
"BasicAuth",
"defines",
"a",
"username",
"and",
"password",
"for",
"HTTP",
"Basic",
"Authentication"
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L187-L190 |
8,571 | h2non/gock | request.go | MatchHeader | func (r *Request) MatchHeader(key, value string) *Request {
r.Header.Set(key, value)
return r
} | go | func (r *Request) MatchHeader(key, value string) *Request {
r.Header.Set(key, value)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"MatchHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // MatchHeader defines a new key and value header to match. | [
"MatchHeader",
"defines",
"a",
"new",
"key",
"and",
"value",
"header",
"to",
"match",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L193-L196 |
8,572 | h2non/gock | request.go | HeaderPresent | func (r *Request) HeaderPresent(key string) *Request {
r.Header.Set(key, ".*")
return r
} | go | func (r *Request) HeaderPresent(key string) *Request {
r.Header.Set(key, ".*")
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"HeaderPresent",
"(",
"key",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // HeaderPresent defines that a header field must be present in the request. | [
"HeaderPresent",
"defines",
"that",
"a",
"header",
"field",
"must",
"be",
"present",
"in",
"the",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L199-L202 |
8,573 | h2non/gock | request.go | MatchHeaders | func (r *Request) MatchHeaders(headers map[string]string) *Request {
for key, value := range headers {
r.Header.Set(key, value)
}
return r
} | go | func (r *Request) MatchHeaders(headers map[string]string) *Request {
for key, value := range headers {
r.Header.Set(key, value)
}
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"MatchHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Request",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"headers",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"key",
",",
"value... | // MatchHeaders defines a map of key-value headers to match. | [
"MatchHeaders",
"defines",
"a",
"map",
"of",
"key",
"-",
"value",
"headers",
"to",
"match",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L205-L210 |
8,574 | h2non/gock | request.go | MatchParam | func (r *Request) MatchParam(key, value string) *Request {
query := r.URLStruct.Query()
query.Set(key, value)
r.URLStruct.RawQuery = query.Encode()
return r
} | go | func (r *Request) MatchParam(key, value string) *Request {
query := r.URLStruct.Query()
query.Set(key, value)
r.URLStruct.RawQuery = query.Encode()
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"MatchParam",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"query",
":=",
"r",
".",
"URLStruct",
".",
"Query",
"(",
")",
"\n",
"query",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"r",
... | // MatchParam defines a new key and value URL query param to match. | [
"MatchParam",
"defines",
"a",
"new",
"key",
"and",
"value",
"URL",
"query",
"param",
"to",
"match",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L213-L218 |
8,575 | h2non/gock | request.go | MatchParams | func (r *Request) MatchParams(params map[string]string) *Request {
query := r.URLStruct.Query()
for key, value := range params {
query.Set(key, value)
}
r.URLStruct.RawQuery = query.Encode()
return r
} | go | func (r *Request) MatchParams(params map[string]string) *Request {
query := r.URLStruct.Query()
for key, value := range params {
query.Set(key, value)
}
r.URLStruct.RawQuery = query.Encode()
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"MatchParams",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Request",
"{",
"query",
":=",
"r",
".",
"URLStruct",
".",
"Query",
"(",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"para... | // MatchParams defines a map of URL query param key-value to match. | [
"MatchParams",
"defines",
"a",
"map",
"of",
"URL",
"query",
"param",
"key",
"-",
"value",
"to",
"match",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L221-L228 |
8,576 | h2non/gock | request.go | ParamPresent | func (r *Request) ParamPresent(key string) *Request {
r.MatchParam(key, ".*")
return r
} | go | func (r *Request) ParamPresent(key string) *Request {
r.MatchParam(key, ".*")
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"ParamPresent",
"(",
"key",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"MatchParam",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // ParamPresent matches if the given query param key is present in the URL. | [
"ParamPresent",
"matches",
"if",
"the",
"given",
"query",
"param",
"key",
"is",
"present",
"in",
"the",
"URL",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L231-L234 |
8,577 | h2non/gock | request.go | Times | func (r *Request) Times(num int) *Request {
r.Counter = num
return r
} | go | func (r *Request) Times(num int) *Request {
r.Counter = num
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Times",
"(",
"num",
"int",
")",
"*",
"Request",
"{",
"r",
".",
"Counter",
"=",
"num",
"\n",
"return",
"r",
"\n",
"}"
] | // Times defines the number of times that the current HTTP mock should remain active. | [
"Times",
"defines",
"the",
"number",
"of",
"times",
"that",
"the",
"current",
"HTTP",
"mock",
"should",
"remain",
"active",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L255-L258 |
8,578 | h2non/gock | request.go | AddMatcher | func (r *Request) AddMatcher(fn MatchFunc) *Request {
r.Mock.AddMatcher(fn)
return r
} | go | func (r *Request) AddMatcher(fn MatchFunc) *Request {
r.Mock.AddMatcher(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"AddMatcher",
"(",
"fn",
"MatchFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Mock",
".",
"AddMatcher",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // AddMatcher adds a new matcher function to match the request. | [
"AddMatcher",
"adds",
"a",
"new",
"matcher",
"function",
"to",
"match",
"the",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L261-L264 |
8,579 | h2non/gock | request.go | SetMatcher | func (r *Request) SetMatcher(matcher Matcher) *Request {
r.Mock.SetMatcher(matcher)
return r
} | go | func (r *Request) SetMatcher(matcher Matcher) *Request {
r.Mock.SetMatcher(matcher)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"SetMatcher",
"(",
"matcher",
"Matcher",
")",
"*",
"Request",
"{",
"r",
".",
"Mock",
".",
"SetMatcher",
"(",
"matcher",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // SetMatcher sets a new matcher function to match the request. | [
"SetMatcher",
"sets",
"a",
"new",
"matcher",
"function",
"to",
"match",
"the",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L267-L270 |
8,580 | h2non/gock | request.go | Map | func (r *Request) Map(fn MapRequestFunc) *Request {
r.Mappers = append(r.Mappers, fn)
return r
} | go | func (r *Request) Map(fn MapRequestFunc) *Request {
r.Mappers = append(r.Mappers, fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Map",
"(",
"fn",
"MapRequestFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Mappers",
"=",
"append",
"(",
"r",
".",
"Mappers",
",",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Map adds a new request mapper function to map http.Request before the matching process. | [
"Map",
"adds",
"a",
"new",
"request",
"mapper",
"function",
"to",
"map",
"http",
".",
"Request",
"before",
"the",
"matching",
"process",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L273-L276 |
8,581 | h2non/gock | request.go | EnableNetworking | func (r *Request) EnableNetworking() *Request {
if r.Response != nil {
r.Response.UseNetwork = true
}
return r
} | go | func (r *Request) EnableNetworking() *Request {
if r.Response != nil {
r.Response.UseNetwork = true
}
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"EnableNetworking",
"(",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"Response",
"!=",
"nil",
"{",
"r",
".",
"Response",
".",
"UseNetwork",
"=",
"true",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // EnableNetworking enables the use real networking for the current mock. | [
"EnableNetworking",
"enables",
"the",
"use",
"real",
"networking",
"for",
"the",
"current",
"mock",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L285-L290 |
8,582 | h2non/gock | request.go | Reply | func (r *Request) Reply(status int) *Response {
return r.Response.Status(status)
} | go | func (r *Request) Reply(status int) *Response {
return r.Response.Status(status)
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Reply",
"(",
"status",
"int",
")",
"*",
"Response",
"{",
"return",
"r",
".",
"Response",
".",
"Status",
"(",
"status",
")",
"\n",
"}"
] | // Reply defines the Response status code and returns the mock Response DSL. | [
"Reply",
"defines",
"the",
"Response",
"status",
"code",
"and",
"returns",
"the",
"mock",
"Response",
"DSL",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L293-L295 |
8,583 | h2non/gock | request.go | ReplyError | func (r *Request) ReplyError(err error) *Response {
return r.Response.SetError(err)
} | go | func (r *Request) ReplyError(err error) *Response {
return r.Response.SetError(err)
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"ReplyError",
"(",
"err",
"error",
")",
"*",
"Response",
"{",
"return",
"r",
".",
"Response",
".",
"SetError",
"(",
"err",
")",
"\n",
"}"
] | // ReplyError defines the Response simulated error. | [
"ReplyError",
"defines",
"the",
"Response",
"simulated",
"error",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L298-L300 |
8,584 | h2non/gock | request.go | ReplyFunc | func (r *Request) ReplyFunc(replier func(*Response)) *Response {
replier(r.Response)
return r.Response
} | go | func (r *Request) ReplyFunc(replier func(*Response)) *Response {
replier(r.Response)
return r.Response
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"ReplyFunc",
"(",
"replier",
"func",
"(",
"*",
"Response",
")",
")",
"*",
"Response",
"{",
"replier",
"(",
"r",
".",
"Response",
")",
"\n",
"return",
"r",
".",
"Response",
"\n",
"}"
] | // ReplyFunc allows the developer to define the mock response via a custom function. | [
"ReplyFunc",
"allows",
"the",
"developer",
"to",
"define",
"the",
"mock",
"response",
"via",
"a",
"custom",
"function",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/request.go#L303-L306 |
8,585 | h2non/gock | responder.go | Responder | func Responder(req *http.Request, mock *Response, res *http.Response) (*http.Response, error) {
// If error present, reply it
err := mock.Error
if err != nil {
return nil, err
}
if res == nil {
res = createResponse(req)
}
// Apply response filter
for _, filter := range mock.Filters {
if !filter(res) {
return res, nil
}
}
// Define mock status code
if mock.StatusCode != 0 {
res.Status = strconv.Itoa(mock.StatusCode) + " " + http.StatusText(mock.StatusCode)
res.StatusCode = mock.StatusCode
}
// Define headers by merging fields
res.Header = mergeHeaders(res, mock)
// Define mock body, if present
if len(mock.BodyBuffer) > 0 {
res.ContentLength = int64(len(mock.BodyBuffer))
res.Body = createReadCloser(mock.BodyBuffer)
}
// Apply response mappers
for _, mapper := range mock.Mappers {
if tres := mapper(res); tres != nil {
res = tres
}
}
// Sleep to simulate delay, if necessary
if mock.ResponseDelay > 0 {
time.Sleep(mock.ResponseDelay)
}
return res, err
} | go | func Responder(req *http.Request, mock *Response, res *http.Response) (*http.Response, error) {
// If error present, reply it
err := mock.Error
if err != nil {
return nil, err
}
if res == nil {
res = createResponse(req)
}
// Apply response filter
for _, filter := range mock.Filters {
if !filter(res) {
return res, nil
}
}
// Define mock status code
if mock.StatusCode != 0 {
res.Status = strconv.Itoa(mock.StatusCode) + " " + http.StatusText(mock.StatusCode)
res.StatusCode = mock.StatusCode
}
// Define headers by merging fields
res.Header = mergeHeaders(res, mock)
// Define mock body, if present
if len(mock.BodyBuffer) > 0 {
res.ContentLength = int64(len(mock.BodyBuffer))
res.Body = createReadCloser(mock.BodyBuffer)
}
// Apply response mappers
for _, mapper := range mock.Mappers {
if tres := mapper(res); tres != nil {
res = tres
}
}
// Sleep to simulate delay, if necessary
if mock.ResponseDelay > 0 {
time.Sleep(mock.ResponseDelay)
}
return res, err
} | [
"func",
"Responder",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"mock",
"*",
"Response",
",",
"res",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"// If error present, reply it",
"err",
":=",
"mock",
... | // Responder builds a mock http.Response based on the given Response mock. | [
"Responder",
"builds",
"a",
"mock",
"http",
".",
"Response",
"based",
"on",
"the",
"given",
"Response",
"mock",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/responder.go#L13-L59 |
8,586 | h2non/gock | responder.go | createResponse | func createResponse(req *http.Request) *http.Response {
return &http.Response{
ProtoMajor: 1,
ProtoMinor: 1,
Proto: "HTTP/1.1",
Request: req,
Header: make(http.Header),
Body: createReadCloser([]byte{}),
}
} | go | func createResponse(req *http.Request) *http.Response {
return &http.Response{
ProtoMajor: 1,
ProtoMinor: 1,
Proto: "HTTP/1.1",
Request: req,
Header: make(http.Header),
Body: createReadCloser([]byte{}),
}
} | [
"func",
"createResponse",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"*",
"http",
".",
"Response",
"{",
"return",
"&",
"http",
".",
"Response",
"{",
"ProtoMajor",
":",
"1",
",",
"ProtoMinor",
":",
"1",
",",
"Proto",
":",
"\"",
"\"",
",",
"Request"... | // createResponse creates a new http.Response with default fields. | [
"createResponse",
"creates",
"a",
"new",
"http",
".",
"Response",
"with",
"default",
"fields",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/responder.go#L62-L71 |
8,587 | h2non/gock | responder.go | mergeHeaders | func mergeHeaders(res *http.Response, mres *Response) http.Header {
for key, values := range mres.Header {
for _, value := range values {
res.Header.Add(key, value)
}
}
return res.Header
} | go | func mergeHeaders(res *http.Response, mres *Response) http.Header {
for key, values := range mres.Header {
for _, value := range values {
res.Header.Add(key, value)
}
}
return res.Header
} | [
"func",
"mergeHeaders",
"(",
"res",
"*",
"http",
".",
"Response",
",",
"mres",
"*",
"Response",
")",
"http",
".",
"Header",
"{",
"for",
"key",
",",
"values",
":=",
"range",
"mres",
".",
"Header",
"{",
"for",
"_",
",",
"value",
":=",
"range",
"values"... | // mergeHeaders copies the mock headers. | [
"mergeHeaders",
"copies",
"the",
"mock",
"headers",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/responder.go#L74-L81 |
8,588 | h2non/gock | responder.go | createReadCloser | func createReadCloser(body []byte) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader(body))
} | go | func createReadCloser(body []byte) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader(body))
} | [
"func",
"createReadCloser",
"(",
"body",
"[",
"]",
"byte",
")",
"io",
".",
"ReadCloser",
"{",
"return",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewReader",
"(",
"body",
")",
")",
"\n",
"}"
] | // createReadCloser creates an io.ReadCloser from a byte slice that is suitable for use as an
// http response body. | [
"createReadCloser",
"creates",
"an",
"io",
".",
"ReadCloser",
"from",
"a",
"byte",
"slice",
"that",
"is",
"suitable",
"for",
"use",
"as",
"an",
"http",
"response",
"body",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/responder.go#L85-L87 |
8,589 | h2non/gock | _examples/networking_partially_enabled/networking.go | startHTTPServer | func startHTTPServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Local server received a GET request")
res, err := http.Get("http://httpbin.org/nope")
if err != nil {
msg := fmt.Sprintf("Error from request to httpbin: %s", err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
body, _ := ioutil.ReadAll(res.Body)
// MUST NOT get original body since the networking
// wasn't enabled for this request
fmt.Printf("Body From httpbin: %s\n", string(body))
fmt.Printf("Status From httpbin: %s\n", res.Status)
io.WriteString(w, "Local Response="+res.Header.Get("Server"))
}))
} | go | func startHTTPServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Local server received a GET request")
res, err := http.Get("http://httpbin.org/nope")
if err != nil {
msg := fmt.Sprintf("Error from request to httpbin: %s", err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
body, _ := ioutil.ReadAll(res.Body)
// MUST NOT get original body since the networking
// wasn't enabled for this request
fmt.Printf("Body From httpbin: %s\n", string(body))
fmt.Printf("Status From httpbin: %s\n", res.Status)
io.WriteString(w, "Local Response="+res.Header.Get("Server"))
}))
} | [
"func",
"startHTTPServer",
"(",
")",
"*",
"httptest",
".",
"Server",
"{",
"return",
"httptest",
".",
"NewServer",
"(",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"f... | // Starts a local HTTP server in background | [
"Starts",
"a",
"local",
"HTTP",
"server",
"in",
"background"
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/_examples/networking_partially_enabled/networking.go#L16-L35 |
8,590 | h2non/gock | matchers.go | MatchMethod | func MatchMethod(req *http.Request, ereq *Request) (bool, error) {
return ereq.Method == "" || req.Method == ereq.Method, nil
} | go | func MatchMethod(req *http.Request, ereq *Request) (bool, error) {
return ereq.Method == "" || req.Method == ereq.Method, nil
} | [
"func",
"MatchMethod",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"ereq",
".",
"Method",
"==",
"\"",
"\"",
"||",
"req",
".",
"Method",
"==",
"ereq",
".",
"Method",
",",
... | // MatchMethod matches the HTTP method of the given request. | [
"MatchMethod",
"matches",
"the",
"HTTP",
"method",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L46-L48 |
8,591 | h2non/gock | matchers.go | MatchScheme | func MatchScheme(req *http.Request, ereq *Request) (bool, error) {
return ereq.URLStruct.Scheme == "" || req.URL.Scheme == "" || ereq.URLStruct.Scheme == req.URL.Scheme, nil
} | go | func MatchScheme(req *http.Request, ereq *Request) (bool, error) {
return ereq.URLStruct.Scheme == "" || req.URL.Scheme == "" || ereq.URLStruct.Scheme == req.URL.Scheme, nil
} | [
"func",
"MatchScheme",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"ereq",
".",
"URLStruct",
".",
"Scheme",
"==",
"\"",
"\"",
"||",
"req",
".",
"URL",
".",
"Scheme",
"=="... | // MatchScheme matches the request URL protocol scheme. | [
"MatchScheme",
"matches",
"the",
"request",
"URL",
"protocol",
"scheme",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L51-L53 |
8,592 | h2non/gock | matchers.go | MatchHost | func MatchHost(req *http.Request, ereq *Request) (bool, error) {
url := ereq.URLStruct
if strings.EqualFold(url.Host, req.URL.Host) {
return true, nil
}
return regexp.MatchString(url.Host, req.URL.Host)
} | go | func MatchHost(req *http.Request, ereq *Request) (bool, error) {
url := ereq.URLStruct
if strings.EqualFold(url.Host, req.URL.Host) {
return true, nil
}
return regexp.MatchString(url.Host, req.URL.Host)
} | [
"func",
"MatchHost",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"url",
":=",
"ereq",
".",
"URLStruct",
"\n",
"if",
"strings",
".",
"EqualFold",
"(",
"url",
".",
"Host",
",",
"req"... | // MatchHost matches the HTTP host header field of the given request. | [
"MatchHost",
"matches",
"the",
"HTTP",
"host",
"header",
"field",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L56-L62 |
8,593 | h2non/gock | matchers.go | MatchPath | func MatchPath(req *http.Request, ereq *Request) (bool, error) {
if req.URL.Path == ereq.URLStruct.Path {
return true, nil
}
return regexp.MatchString(ereq.URLStruct.Path, req.URL.Path)
} | go | func MatchPath(req *http.Request, ereq *Request) (bool, error) {
if req.URL.Path == ereq.URLStruct.Path {
return true, nil
}
return regexp.MatchString(ereq.URLStruct.Path, req.URL.Path)
} | [
"func",
"MatchPath",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"req",
".",
"URL",
".",
"Path",
"==",
"ereq",
".",
"URLStruct",
".",
"Path",
"{",
"return",
"true",
",",
"n... | // MatchPath matches the HTTP URL path of the given request. | [
"MatchPath",
"matches",
"the",
"HTTP",
"URL",
"path",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L65-L70 |
8,594 | h2non/gock | matchers.go | MatchHeaders | func MatchHeaders(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.Header {
var err error
var match bool
for _, field := range req.Header[key] {
match, err = regexp.MatchString(value[0], field)
if err != nil {
return false, err
}
if match {
break
}
}
if !match {
return false, nil
}
}
return true, nil
} | go | func MatchHeaders(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.Header {
var err error
var match bool
for _, field := range req.Header[key] {
match, err = regexp.MatchString(value[0], field)
if err != nil {
return false, err
}
if match {
break
}
}
if !match {
return false, nil
}
}
return true, nil
} | [
"func",
"MatchHeaders",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"ereq",
".",
"Header",
"{",
"var",
"err",
"error",
"\n",
"var",
"matc... | // MatchHeaders matches the headers fields of the given request. | [
"MatchHeaders",
"matches",
"the",
"headers",
"fields",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L73-L93 |
8,595 | h2non/gock | matchers.go | MatchQueryParams | func MatchQueryParams(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.URLStruct.Query() {
var err error
var match bool
for _, field := range req.URL.Query()[key] {
match, err = regexp.MatchString(value[0], field)
if err != nil {
return false, err
}
if match {
break
}
}
if !match {
return false, nil
}
}
return true, nil
} | go | func MatchQueryParams(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.URLStruct.Query() {
var err error
var match bool
for _, field := range req.URL.Query()[key] {
match, err = regexp.MatchString(value[0], field)
if err != nil {
return false, err
}
if match {
break
}
}
if !match {
return false, nil
}
}
return true, nil
} | [
"func",
"MatchQueryParams",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"ereq",
".",
"URLStruct",
".",
"Query",
"(",
")",
"{",
"var",
"er... | // MatchQueryParams matches the URL query params fields of the given request. | [
"MatchQueryParams",
"matches",
"the",
"URL",
"query",
"params",
"fields",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L96-L116 |
8,596 | h2non/gock | matchers.go | MatchPathParams | func MatchPathParams(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.PathParams {
var s string
if err := parth.Sequent(req.URL.Path, key, &s); err != nil {
return false, nil
}
if s != value {
return false, nil
}
}
return true, nil
} | go | func MatchPathParams(req *http.Request, ereq *Request) (bool, error) {
for key, value := range ereq.PathParams {
var s string
if err := parth.Sequent(req.URL.Path, key, &s); err != nil {
return false, nil
}
if s != value {
return false, nil
}
}
return true, nil
} | [
"func",
"MatchPathParams",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"ereq",
"*",
"Request",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"ereq",
".",
"PathParams",
"{",
"var",
"s",
"string",
"\n\n",
"if",
... | // MatchPathParams matches the URL path parameters of the given request. | [
"MatchPathParams",
"matches",
"the",
"URL",
"path",
"parameters",
"of",
"the",
"given",
"request",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/matchers.go#L119-L132 |
8,597 | h2non/gock | response.go | Status | func (r *Response) Status(code int) *Response {
r.StatusCode = code
return r
} | go | func (r *Response) Status(code int) *Response {
r.StatusCode = code
return r
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Status",
"(",
"code",
"int",
")",
"*",
"Response",
"{",
"r",
".",
"StatusCode",
"=",
"code",
"\n",
"return",
"r",
"\n",
"}"
] | // Status defines the desired HTTP status code to reply in the current response. | [
"Status",
"defines",
"the",
"desired",
"HTTP",
"status",
"code",
"to",
"reply",
"in",
"the",
"current",
"response",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/response.go#L59-L62 |
8,598 | h2non/gock | response.go | SetHeader | func (r *Response) SetHeader(key, value string) *Response {
r.Header.Set(key, value)
return r
} | go | func (r *Response) SetHeader(key, value string) *Response {
r.Header.Set(key, value)
return r
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"SetHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Response",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // SetHeader sets a new header field in the mock response. | [
"SetHeader",
"sets",
"a",
"new",
"header",
"field",
"in",
"the",
"mock",
"response",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/response.go#L76-L79 |
8,599 | h2non/gock | response.go | AddHeader | func (r *Response) AddHeader(key, value string) *Response {
r.Header.Add(key, value)
return r
} | go | func (r *Response) AddHeader(key, value string) *Response {
r.Header.Add(key, value)
return r
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"AddHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Response",
"{",
"r",
".",
"Header",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // AddHeader adds a new header field in the mock response
// with out removing an existent one. | [
"AddHeader",
"adds",
"a",
"new",
"header",
"field",
"in",
"the",
"mock",
"response",
"with",
"out",
"removing",
"an",
"existent",
"one",
"."
] | 090e9d9644e4961e7084159b80b64ebca1497299 | https://github.com/h2non/gock/blob/090e9d9644e4961e7084159b80b64ebca1497299/response.go#L83-L86 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.