repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilosa/pilosa
|
row.go
|
Shift
|
func (s *rowSegment) Shift() (*rowSegment, error) {
//TODO deal with overflow
data, err := s.data.Shift(1)
if err != nil {
return nil, errors.Wrap(err, "shifting roaring data")
}
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}, nil
}
|
go
|
func (s *rowSegment) Shift() (*rowSegment, error) {
//TODO deal with overflow
data, err := s.data.Shift(1)
if err != nil {
return nil, errors.Wrap(err, "shifting roaring data")
}
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
}, nil
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Shift",
"(",
")",
"(",
"*",
"rowSegment",
",",
"error",
")",
"{",
"//TODO deal with overflow",
"data",
",",
"err",
":=",
"s",
".",
"data",
".",
"Shift",
"(",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"rowSegment",
"{",
"data",
":",
"*",
"data",
",",
"shard",
":",
"s",
".",
"shard",
",",
"n",
":",
"data",
".",
"Count",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Shift returns s shifted by 1 bit.
|
[
"Shift",
"returns",
"s",
"shifted",
"by",
"1",
"bit",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L373-L385
|
train
|
pilosa/pilosa
|
row.go
|
ClearBit
|
func (s *rowSegment) ClearBit(i uint64) (changed bool) {
s.ensureWritable()
changed, _ = s.data.Remove(i)
if changed {
s.n--
}
return changed
}
|
go
|
func (s *rowSegment) ClearBit(i uint64) (changed bool) {
s.ensureWritable()
changed, _ = s.data.Remove(i)
if changed {
s.n--
}
return changed
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"ClearBit",
"(",
"i",
"uint64",
")",
"(",
"changed",
"bool",
")",
"{",
"s",
".",
"ensureWritable",
"(",
")",
"\n\n",
"changed",
",",
"_",
"=",
"s",
".",
"data",
".",
"Remove",
"(",
"i",
")",
"\n",
"if",
"changed",
"{",
"s",
".",
"n",
"--",
"\n",
"}",
"\n",
"return",
"changed",
"\n",
"}"
] |
// ClearBit clears the i-th column of the row.
|
[
"ClearBit",
"clears",
"the",
"i",
"-",
"th",
"column",
"of",
"the",
"row",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L398-L406
|
train
|
pilosa/pilosa
|
row.go
|
Columns
|
func (s *rowSegment) Columns() []uint64 {
a := make([]uint64, 0, s.Count())
itr := s.data.Iterator()
for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
a = append(a, v)
}
return a
}
|
go
|
func (s *rowSegment) Columns() []uint64 {
a := make([]uint64, 0, s.Count())
itr := s.data.Iterator()
for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
a = append(a, v)
}
return a
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"Columns",
"(",
")",
"[",
"]",
"uint64",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"s",
".",
"Count",
"(",
")",
")",
"\n",
"itr",
":=",
"s",
".",
"data",
".",
"Iterator",
"(",
")",
"\n",
"for",
"v",
",",
"eof",
":=",
"itr",
".",
"Next",
"(",
")",
";",
"!",
"eof",
";",
"v",
",",
"eof",
"=",
"itr",
".",
"Next",
"(",
")",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] |
// Columns returns a list of all columns set in the segment.
|
[
"Columns",
"returns",
"a",
"list",
"of",
"all",
"columns",
"set",
"in",
"the",
"segment",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L414-L421
|
train
|
pilosa/pilosa
|
row.go
|
ensureWritable
|
func (s *rowSegment) ensureWritable() {
if s.writable {
return
}
s.data = *s.data.Clone()
s.writable = true
}
|
go
|
func (s *rowSegment) ensureWritable() {
if s.writable {
return
}
s.data = *s.data.Clone()
s.writable = true
}
|
[
"func",
"(",
"s",
"*",
"rowSegment",
")",
"ensureWritable",
"(",
")",
"{",
"if",
"s",
".",
"writable",
"{",
"return",
"\n",
"}",
"\n\n",
"s",
".",
"data",
"=",
"*",
"s",
".",
"data",
".",
"Clone",
"(",
")",
"\n",
"s",
".",
"writable",
"=",
"true",
"\n",
"}"
] |
// ensureWritable clones the segment if it is pointing to non-writable data.
|
[
"ensureWritable",
"clones",
"the",
"segment",
"if",
"it",
"is",
"pointing",
"to",
"non",
"-",
"writable",
"data",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L427-L434
|
train
|
pilosa/pilosa
|
row.go
|
newMergeSegmentIterator
|
func newMergeSegmentIterator(a0, a1 []rowSegment) mergeSegmentIterator {
return mergeSegmentIterator{a0: a0, a1: a1}
}
|
go
|
func newMergeSegmentIterator(a0, a1 []rowSegment) mergeSegmentIterator {
return mergeSegmentIterator{a0: a0, a1: a1}
}
|
[
"func",
"newMergeSegmentIterator",
"(",
"a0",
",",
"a1",
"[",
"]",
"rowSegment",
")",
"mergeSegmentIterator",
"{",
"return",
"mergeSegmentIterator",
"{",
"a0",
":",
"a0",
",",
"a1",
":",
"a1",
"}",
"\n",
"}"
] |
// newMergeSegmentIterator returns a new instance of mergeSegmentIterator.
|
[
"newMergeSegmentIterator",
"returns",
"a",
"new",
"instance",
"of",
"mergeSegmentIterator",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L442-L444
|
train
|
pilosa/pilosa
|
row.go
|
next
|
func (itr *mergeSegmentIterator) next() (s0, s1 *rowSegment) {
// Find current segments.
if len(itr.a0) > 0 {
s0 = &itr.a0[0]
}
if len(itr.a1) > 0 {
s1 = &itr.a1[0]
}
// Return if either or both are nil.
if s0 == nil && s1 == nil {
return
} else if s0 == nil {
itr.a1 = itr.a1[1:]
return
} else if s1 == nil {
itr.a0 = itr.a0[1:]
return
}
// Otherwise determine which is first.
if s0.shard < s1.shard {
itr.a0 = itr.a0[1:]
return s0, nil
} else if s0.shard > s1.shard {
itr.a1 = itr.a1[1:]
return s1, nil
}
// Return both if shards are equal.
itr.a0, itr.a1 = itr.a0[1:], itr.a1[1:]
return s0, s1
}
|
go
|
func (itr *mergeSegmentIterator) next() (s0, s1 *rowSegment) {
// Find current segments.
if len(itr.a0) > 0 {
s0 = &itr.a0[0]
}
if len(itr.a1) > 0 {
s1 = &itr.a1[0]
}
// Return if either or both are nil.
if s0 == nil && s1 == nil {
return
} else if s0 == nil {
itr.a1 = itr.a1[1:]
return
} else if s1 == nil {
itr.a0 = itr.a0[1:]
return
}
// Otherwise determine which is first.
if s0.shard < s1.shard {
itr.a0 = itr.a0[1:]
return s0, nil
} else if s0.shard > s1.shard {
itr.a1 = itr.a1[1:]
return s1, nil
}
// Return both if shards are equal.
itr.a0, itr.a1 = itr.a0[1:], itr.a1[1:]
return s0, s1
}
|
[
"func",
"(",
"itr",
"*",
"mergeSegmentIterator",
")",
"next",
"(",
")",
"(",
"s0",
",",
"s1",
"*",
"rowSegment",
")",
"{",
"// Find current segments.",
"if",
"len",
"(",
"itr",
".",
"a0",
")",
">",
"0",
"{",
"s0",
"=",
"&",
"itr",
".",
"a0",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"itr",
".",
"a1",
")",
">",
"0",
"{",
"s1",
"=",
"&",
"itr",
".",
"a1",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"// Return if either or both are nil.",
"if",
"s0",
"==",
"nil",
"&&",
"s1",
"==",
"nil",
"{",
"return",
"\n",
"}",
"else",
"if",
"s0",
"==",
"nil",
"{",
"itr",
".",
"a1",
"=",
"itr",
".",
"a1",
"[",
"1",
":",
"]",
"\n",
"return",
"\n",
"}",
"else",
"if",
"s1",
"==",
"nil",
"{",
"itr",
".",
"a0",
"=",
"itr",
".",
"a0",
"[",
"1",
":",
"]",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Otherwise determine which is first.",
"if",
"s0",
".",
"shard",
"<",
"s1",
".",
"shard",
"{",
"itr",
".",
"a0",
"=",
"itr",
".",
"a0",
"[",
"1",
":",
"]",
"\n",
"return",
"s0",
",",
"nil",
"\n",
"}",
"else",
"if",
"s0",
".",
"shard",
">",
"s1",
".",
"shard",
"{",
"itr",
".",
"a1",
"=",
"itr",
".",
"a1",
"[",
"1",
":",
"]",
"\n",
"return",
"s1",
",",
"nil",
"\n",
"}",
"\n\n",
"// Return both if shards are equal.",
"itr",
".",
"a0",
",",
"itr",
".",
"a1",
"=",
"itr",
".",
"a0",
"[",
"1",
":",
"]",
",",
"itr",
".",
"a1",
"[",
"1",
":",
"]",
"\n",
"return",
"s0",
",",
"s1",
"\n",
"}"
] |
// next returns the next set of segments.
|
[
"next",
"returns",
"the",
"next",
"set",
"of",
"segments",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/row.go#L447-L479
|
train
|
pilosa/pilosa
|
internal/internal.go
|
Encode
|
func (enc *Encoder) Encode(pb proto.Message) error {
buf, err := proto.Marshal(pb)
if err != nil {
return err
}
if _, err := enc.w.Write(buf); err != nil {
return err
}
return nil
}
|
go
|
func (enc *Encoder) Encode(pb proto.Message) error {
buf, err := proto.Marshal(pb)
if err != nil {
return err
}
if _, err := enc.w.Write(buf); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"enc",
"*",
"Encoder",
")",
"Encode",
"(",
"pb",
"proto",
".",
"Message",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"enc",
".",
"w",
".",
"Write",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Encode marshals m into bytes and writes them to r.
|
[
"Encode",
"marshals",
"m",
"into",
"bytes",
"and",
"writes",
"them",
"to",
"r",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/internal/internal.go#L42-L53
|
train
|
pilosa/pilosa
|
internal/internal.go
|
Decode
|
func (dec *Decoder) Decode(pb proto.Message) error {
buf, err := ioutil.ReadAll(dec.r)
if err != nil {
return err
}
return proto.Unmarshal(buf, pb)
}
|
go
|
func (dec *Decoder) Decode(pb proto.Message) error {
buf, err := ioutil.ReadAll(dec.r)
if err != nil {
return err
}
return proto.Unmarshal(buf, pb)
}
|
[
"func",
"(",
"dec",
"*",
"Decoder",
")",
"Decode",
"(",
"pb",
"proto",
".",
"Message",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"dec",
".",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"pb",
")",
"\n",
"}"
] |
// Decode reads all bytes from the reader and unmarshals them into pb.
|
[
"Decode",
"reads",
"all",
"bytes",
"from",
"the",
"reader",
"and",
"unmarshals",
"them",
"into",
"pb",
"."
] |
67d53f6b48a43f7fe090f48e35518ca8d024747c
|
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/internal/internal.go#L66-L73
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
MarshalJSON
|
func (t *ButtonsTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
ThumbnailImageURL string `json:"thumbnailImageUrl,omitempty"`
ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"`
ImageSize ImageSizeType `json:"imageSize,omitempty"`
ImageBackgroundColor string `json:"imageBackgroundColor,omitempty"`
Title string `json:"title,omitempty"`
Text string `json:"text"`
Actions []TemplateAction `json:"actions"`
}{
Type: TemplateTypeButtons,
ThumbnailImageURL: t.ThumbnailImageURL,
ImageAspectRatio: t.ImageAspectRatio,
ImageSize: t.ImageSize,
ImageBackgroundColor: t.ImageBackgroundColor,
Title: t.Title,
Text: t.Text,
Actions: t.Actions,
})
}
|
go
|
func (t *ButtonsTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
ThumbnailImageURL string `json:"thumbnailImageUrl,omitempty"`
ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"`
ImageSize ImageSizeType `json:"imageSize,omitempty"`
ImageBackgroundColor string `json:"imageBackgroundColor,omitempty"`
Title string `json:"title,omitempty"`
Text string `json:"text"`
Actions []TemplateAction `json:"actions"`
}{
Type: TemplateTypeButtons,
ThumbnailImageURL: t.ThumbnailImageURL,
ImageAspectRatio: t.ImageAspectRatio,
ImageSize: t.ImageSize,
ImageBackgroundColor: t.ImageBackgroundColor,
Title: t.Title,
Text: t.Text,
Actions: t.Actions,
})
}
|
[
"func",
"(",
"t",
"*",
"ButtonsTemplate",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"TemplateType",
"`json:\"type\"`",
"\n",
"ThumbnailImageURL",
"string",
"`json:\"thumbnailImageUrl,omitempty\"`",
"\n",
"ImageAspectRatio",
"ImageAspectRatioType",
"`json:\"imageAspectRatio,omitempty\"`",
"\n",
"ImageSize",
"ImageSizeType",
"`json:\"imageSize,omitempty\"`",
"\n",
"ImageBackgroundColor",
"string",
"`json:\"imageBackgroundColor,omitempty\"`",
"\n",
"Title",
"string",
"`json:\"title,omitempty\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"Actions",
"[",
"]",
"TemplateAction",
"`json:\"actions\"`",
"\n",
"}",
"{",
"Type",
":",
"TemplateTypeButtons",
",",
"ThumbnailImageURL",
":",
"t",
".",
"ThumbnailImageURL",
",",
"ImageAspectRatio",
":",
"t",
".",
"ImageAspectRatio",
",",
"ImageSize",
":",
"t",
".",
"ImageSize",
",",
"ImageBackgroundColor",
":",
"t",
".",
"ImageBackgroundColor",
",",
"Title",
":",
"t",
".",
"Title",
",",
"Text",
":",
"t",
".",
"Text",
",",
"Actions",
":",
"t",
".",
"Actions",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ButtonsTemplate
|
[
"MarshalJSON",
"method",
"of",
"ButtonsTemplate"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L68-L88
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
WithImageOptions
|
func (t *ButtonsTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType, imageBackgroundColor string) *ButtonsTemplate {
t.ImageAspectRatio = imageAspectRatio
t.ImageSize = imageSize
t.ImageBackgroundColor = imageBackgroundColor
return t
}
|
go
|
func (t *ButtonsTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType, imageBackgroundColor string) *ButtonsTemplate {
t.ImageAspectRatio = imageAspectRatio
t.ImageSize = imageSize
t.ImageBackgroundColor = imageBackgroundColor
return t
}
|
[
"func",
"(",
"t",
"*",
"ButtonsTemplate",
")",
"WithImageOptions",
"(",
"imageAspectRatio",
"ImageAspectRatioType",
",",
"imageSize",
"ImageSizeType",
",",
"imageBackgroundColor",
"string",
")",
"*",
"ButtonsTemplate",
"{",
"t",
".",
"ImageAspectRatio",
"=",
"imageAspectRatio",
"\n",
"t",
".",
"ImageSize",
"=",
"imageSize",
"\n",
"t",
".",
"ImageBackgroundColor",
"=",
"imageBackgroundColor",
"\n",
"return",
"t",
"\n",
"}"
] |
// WithImageOptions method, ButtonsTemplate can set imageAspectRatio, imageSize and imageBackgroundColor
|
[
"WithImageOptions",
"method",
"ButtonsTemplate",
"can",
"set",
"imageAspectRatio",
"imageSize",
"and",
"imageBackgroundColor"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L91-L96
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
MarshalJSON
|
func (t *ConfirmTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Text string `json:"text"`
Actions []TemplateAction `json:"actions"`
}{
Type: TemplateTypeConfirm,
Text: t.Text,
Actions: t.Actions,
})
}
|
go
|
func (t *ConfirmTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Text string `json:"text"`
Actions []TemplateAction `json:"actions"`
}{
Type: TemplateTypeConfirm,
Text: t.Text,
Actions: t.Actions,
})
}
|
[
"func",
"(",
"t",
"*",
"ConfirmTemplate",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"TemplateType",
"`json:\"type\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"Actions",
"[",
"]",
"TemplateAction",
"`json:\"actions\"`",
"\n",
"}",
"{",
"Type",
":",
"TemplateTypeConfirm",
",",
"Text",
":",
"t",
".",
"Text",
",",
"Actions",
":",
"t",
".",
"Actions",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ConfirmTemplate
|
[
"MarshalJSON",
"method",
"of",
"ConfirmTemplate"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L105-L115
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
MarshalJSON
|
func (t *CarouselTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Columns []*CarouselColumn `json:"columns"`
ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"`
ImageSize ImageSizeType `json:"imageSize,omitempty"`
}{
Type: TemplateTypeCarousel,
Columns: t.Columns,
ImageAspectRatio: t.ImageAspectRatio,
ImageSize: t.ImageSize,
})
}
|
go
|
func (t *CarouselTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Columns []*CarouselColumn `json:"columns"`
ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"`
ImageSize ImageSizeType `json:"imageSize,omitempty"`
}{
Type: TemplateTypeCarousel,
Columns: t.Columns,
ImageAspectRatio: t.ImageAspectRatio,
ImageSize: t.ImageSize,
})
}
|
[
"func",
"(",
"t",
"*",
"CarouselTemplate",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"TemplateType",
"`json:\"type\"`",
"\n",
"Columns",
"[",
"]",
"*",
"CarouselColumn",
"`json:\"columns\"`",
"\n",
"ImageAspectRatio",
"ImageAspectRatioType",
"`json:\"imageAspectRatio,omitempty\"`",
"\n",
"ImageSize",
"ImageSizeType",
"`json:\"imageSize,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"TemplateTypeCarousel",
",",
"Columns",
":",
"t",
".",
"Columns",
",",
"ImageAspectRatio",
":",
"t",
".",
"ImageAspectRatio",
",",
"ImageSize",
":",
"t",
".",
"ImageSize",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of CarouselTemplate
|
[
"MarshalJSON",
"method",
"of",
"CarouselTemplate"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L134-L146
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
WithImageOptions
|
func (t *CarouselTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType) *CarouselTemplate {
t.ImageAspectRatio = imageAspectRatio
t.ImageSize = imageSize
return t
}
|
go
|
func (t *CarouselTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType) *CarouselTemplate {
t.ImageAspectRatio = imageAspectRatio
t.ImageSize = imageSize
return t
}
|
[
"func",
"(",
"t",
"*",
"CarouselTemplate",
")",
"WithImageOptions",
"(",
"imageAspectRatio",
"ImageAspectRatioType",
",",
"imageSize",
"ImageSizeType",
")",
"*",
"CarouselTemplate",
"{",
"t",
".",
"ImageAspectRatio",
"=",
"imageAspectRatio",
"\n",
"t",
".",
"ImageSize",
"=",
"imageSize",
"\n",
"return",
"t",
"\n",
"}"
] |
// WithImageOptions method, CarouselTemplate can set imageAspectRatio and imageSize
|
[
"WithImageOptions",
"method",
"CarouselTemplate",
"can",
"set",
"imageAspectRatio",
"and",
"imageSize"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L149-L153
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
WithImageOptions
|
func (t *CarouselColumn) WithImageOptions(imageBackgroundColor string) *CarouselColumn {
t.ImageBackgroundColor = imageBackgroundColor
return t
}
|
go
|
func (t *CarouselColumn) WithImageOptions(imageBackgroundColor string) *CarouselColumn {
t.ImageBackgroundColor = imageBackgroundColor
return t
}
|
[
"func",
"(",
"t",
"*",
"CarouselColumn",
")",
"WithImageOptions",
"(",
"imageBackgroundColor",
"string",
")",
"*",
"CarouselColumn",
"{",
"t",
".",
"ImageBackgroundColor",
"=",
"imageBackgroundColor",
"\n",
"return",
"t",
"\n",
"}"
] |
// WithImageOptions method, CarouselColumn can set imageBackgroundColor
|
[
"WithImageOptions",
"method",
"CarouselColumn",
"can",
"set",
"imageBackgroundColor"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L156-L159
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
MarshalJSON
|
func (t *ImageCarouselTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Columns []*ImageCarouselColumn `json:"columns"`
}{
Type: TemplateTypeImageCarousel,
Columns: t.Columns,
})
}
|
go
|
func (t *ImageCarouselTemplate) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type TemplateType `json:"type"`
Columns []*ImageCarouselColumn `json:"columns"`
}{
Type: TemplateTypeImageCarousel,
Columns: t.Columns,
})
}
|
[
"func",
"(",
"t",
"*",
"ImageCarouselTemplate",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"TemplateType",
"`json:\"type\"`",
"\n",
"Columns",
"[",
"]",
"*",
"ImageCarouselColumn",
"`json:\"columns\"`",
"\n",
"}",
"{",
"Type",
":",
"TemplateTypeImageCarousel",
",",
"Columns",
":",
"t",
".",
"Columns",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ImageCarouselTemplate
|
[
"MarshalJSON",
"method",
"of",
"ImageCarouselTemplate"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L173-L181
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
NewButtonsTemplate
|
func NewButtonsTemplate(thumbnailImageURL, title, text string, actions ...TemplateAction) *ButtonsTemplate {
return &ButtonsTemplate{
ThumbnailImageURL: thumbnailImageURL,
Title: title,
Text: text,
Actions: actions,
}
}
|
go
|
func NewButtonsTemplate(thumbnailImageURL, title, text string, actions ...TemplateAction) *ButtonsTemplate {
return &ButtonsTemplate{
ThumbnailImageURL: thumbnailImageURL,
Title: title,
Text: text,
Actions: actions,
}
}
|
[
"func",
"NewButtonsTemplate",
"(",
"thumbnailImageURL",
",",
"title",
",",
"text",
"string",
",",
"actions",
"...",
"TemplateAction",
")",
"*",
"ButtonsTemplate",
"{",
"return",
"&",
"ButtonsTemplate",
"{",
"ThumbnailImageURL",
":",
"thumbnailImageURL",
",",
"Title",
":",
"title",
",",
"Text",
":",
"text",
",",
"Actions",
":",
"actions",
",",
"}",
"\n",
"}"
] |
// NewButtonsTemplate function
// `thumbnailImageURL` and `title` are optional. they can be empty.
|
[
"NewButtonsTemplate",
"function",
"thumbnailImageURL",
"and",
"title",
"are",
"optional",
".",
"they",
"can",
"be",
"empty",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L205-L212
|
train
|
line/line-bot-sdk-go
|
linebot/template.go
|
NewCarouselColumn
|
func NewCarouselColumn(thumbnailImageURL, title, text string, actions ...TemplateAction) *CarouselColumn {
return &CarouselColumn{
ThumbnailImageURL: thumbnailImageURL,
Title: title,
Text: text,
Actions: actions,
}
}
|
go
|
func NewCarouselColumn(thumbnailImageURL, title, text string, actions ...TemplateAction) *CarouselColumn {
return &CarouselColumn{
ThumbnailImageURL: thumbnailImageURL,
Title: title,
Text: text,
Actions: actions,
}
}
|
[
"func",
"NewCarouselColumn",
"(",
"thumbnailImageURL",
",",
"title",
",",
"text",
"string",
",",
"actions",
"...",
"TemplateAction",
")",
"*",
"CarouselColumn",
"{",
"return",
"&",
"CarouselColumn",
"{",
"ThumbnailImageURL",
":",
"thumbnailImageURL",
",",
"Title",
":",
"title",
",",
"Text",
":",
"text",
",",
"Actions",
":",
"actions",
",",
"}",
"\n",
"}"
] |
// NewCarouselColumn function
// `thumbnailImageURL` and `title` are optional. they can be empty.
|
[
"NewCarouselColumn",
"function",
"thumbnailImageURL",
"and",
"title",
"are",
"optional",
".",
"they",
"can",
"be",
"empty",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/template.go#L223-L230
|
train
|
line/line-bot-sdk-go
|
linebot/imagemap.go
|
MarshalJSON
|
func (a *URIImagemapAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ImagemapActionType `json:"type"`
LinkURL string `json:"linkUri"`
Area ImagemapArea `json:"area"`
}{
Type: ImagemapActionTypeURI,
LinkURL: a.LinkURL,
Area: a.Area,
})
}
|
go
|
func (a *URIImagemapAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ImagemapActionType `json:"type"`
LinkURL string `json:"linkUri"`
Area ImagemapArea `json:"area"`
}{
Type: ImagemapActionTypeURI,
LinkURL: a.LinkURL,
Area: a.Area,
})
}
|
[
"func",
"(",
"a",
"*",
"URIImagemapAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ImagemapActionType",
"`json:\"type\"`",
"\n",
"LinkURL",
"string",
"`json:\"linkUri\"`",
"\n",
"Area",
"ImagemapArea",
"`json:\"area\"`",
"\n",
"}",
"{",
"Type",
":",
"ImagemapActionTypeURI",
",",
"LinkURL",
":",
"a",
".",
"LinkURL",
",",
"Area",
":",
"a",
".",
"Area",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of URIImagemapAction
|
[
"MarshalJSON",
"method",
"of",
"URIImagemapAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/imagemap.go#L71-L81
|
train
|
line/line-bot-sdk-go
|
linebot/imagemap.go
|
MarshalJSON
|
func (a *MessageImagemapAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ImagemapActionType `json:"type"`
Text string `json:"text"`
Area ImagemapArea `json:"area"`
}{
Type: ImagemapActionTypeMessage,
Text: a.Text,
Area: a.Area,
})
}
|
go
|
func (a *MessageImagemapAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ImagemapActionType `json:"type"`
Text string `json:"text"`
Area ImagemapArea `json:"area"`
}{
Type: ImagemapActionTypeMessage,
Text: a.Text,
Area: a.Area,
})
}
|
[
"func",
"(",
"a",
"*",
"MessageImagemapAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ImagemapActionType",
"`json:\"type\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"Area",
"ImagemapArea",
"`json:\"area\"`",
"\n",
"}",
"{",
"Type",
":",
"ImagemapActionTypeMessage",
",",
"Text",
":",
"a",
".",
"Text",
",",
"Area",
":",
"a",
".",
"Area",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of MessageImagemapAction
|
[
"MarshalJSON",
"method",
"of",
"MessageImagemapAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/imagemap.go#L90-L100
|
train
|
line/line-bot-sdk-go
|
linebot/client.go
|
New
|
func New(channelSecret, channelToken string, options ...ClientOption) (*Client, error) {
if channelSecret == "" {
return nil, errors.New("missing channel secret")
}
if channelToken == "" {
return nil, errors.New("missing channel access token")
}
c := &Client{
channelSecret: channelSecret,
channelToken: channelToken,
httpClient: http.DefaultClient,
}
for _, option := range options {
err := option(c)
if err != nil {
return nil, err
}
}
if c.endpointBase == nil {
u, err := url.ParseRequestURI(APIEndpointBase)
if err != nil {
return nil, err
}
c.endpointBase = u
}
return c, nil
}
|
go
|
func New(channelSecret, channelToken string, options ...ClientOption) (*Client, error) {
if channelSecret == "" {
return nil, errors.New("missing channel secret")
}
if channelToken == "" {
return nil, errors.New("missing channel access token")
}
c := &Client{
channelSecret: channelSecret,
channelToken: channelToken,
httpClient: http.DefaultClient,
}
for _, option := range options {
err := option(c)
if err != nil {
return nil, err
}
}
if c.endpointBase == nil {
u, err := url.ParseRequestURI(APIEndpointBase)
if err != nil {
return nil, err
}
c.endpointBase = u
}
return c, nil
}
|
[
"func",
"New",
"(",
"channelSecret",
",",
"channelToken",
"string",
",",
"options",
"...",
"ClientOption",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"channelSecret",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"channelToken",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
":=",
"&",
"Client",
"{",
"channelSecret",
":",
"channelSecret",
",",
"channelToken",
":",
"channelToken",
",",
"httpClient",
":",
"http",
".",
"DefaultClient",
",",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"err",
":=",
"option",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"endpointBase",
"==",
"nil",
"{",
"u",
",",
"err",
":=",
"url",
".",
"ParseRequestURI",
"(",
"APIEndpointBase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"endpointBase",
"=",
"u",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// New returns a new bot client instance.
|
[
"New",
"returns",
"a",
"new",
"bot",
"client",
"instance",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/client.go#L79-L105
|
train
|
line/line-bot-sdk-go
|
linebot/flex_unmarshal.go
|
UnmarshalJSON
|
func (c *BoxComponent) UnmarshalJSON(data []byte) error {
type alias BoxComponent
raw := struct {
Contents []rawFlexComponent `json:"contents"`
*alias
}{
alias: (*alias)(c),
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
components := make([]FlexComponent, len(raw.Contents))
for i, content := range raw.Contents {
components[i] = content.Component
}
c.Contents = components
return nil
}
|
go
|
func (c *BoxComponent) UnmarshalJSON(data []byte) error {
type alias BoxComponent
raw := struct {
Contents []rawFlexComponent `json:"contents"`
*alias
}{
alias: (*alias)(c),
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
components := make([]FlexComponent, len(raw.Contents))
for i, content := range raw.Contents {
components[i] = content.Component
}
c.Contents = components
return nil
}
|
[
"func",
"(",
"c",
"*",
"BoxComponent",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"type",
"alias",
"BoxComponent",
"\n",
"raw",
":=",
"struct",
"{",
"Contents",
"[",
"]",
"rawFlexComponent",
"`json:\"contents\"`",
"\n",
"*",
"alias",
"\n",
"}",
"{",
"alias",
":",
"(",
"*",
"alias",
")",
"(",
"c",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"raw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"components",
":=",
"make",
"(",
"[",
"]",
"FlexComponent",
",",
"len",
"(",
"raw",
".",
"Contents",
")",
")",
"\n",
"for",
"i",
",",
"content",
":=",
"range",
"raw",
".",
"Contents",
"{",
"components",
"[",
"i",
"]",
"=",
"content",
".",
"Component",
"\n",
"}",
"\n",
"c",
".",
"Contents",
"=",
"components",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON method for BoxComponent
|
[
"UnmarshalJSON",
"method",
"for",
"BoxComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex_unmarshal.go#L132-L149
|
train
|
line/line-bot-sdk-go
|
linebot/flex_unmarshal.go
|
UnmarshalJSON
|
func (c *ButtonComponent) UnmarshalJSON(data []byte) error {
type alias ButtonComponent
raw := struct {
Action rawAction `json:"action"`
*alias
}{
alias: (*alias)(c),
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
c.Action = raw.Action.Action
return nil
}
|
go
|
func (c *ButtonComponent) UnmarshalJSON(data []byte) error {
type alias ButtonComponent
raw := struct {
Action rawAction `json:"action"`
*alias
}{
alias: (*alias)(c),
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
c.Action = raw.Action.Action
return nil
}
|
[
"func",
"(",
"c",
"*",
"ButtonComponent",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"type",
"alias",
"ButtonComponent",
"\n",
"raw",
":=",
"struct",
"{",
"Action",
"rawAction",
"`json:\"action\"`",
"\n",
"*",
"alias",
"\n",
"}",
"{",
"alias",
":",
"(",
"*",
"alias",
")",
"(",
"c",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"raw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"Action",
"=",
"raw",
".",
"Action",
".",
"Action",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON method for ButtonComponent
|
[
"UnmarshalJSON",
"method",
"for",
"ButtonComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex_unmarshal.go#L152-L165
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *BubbleContainer) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexContainerType `json:"type"`
Direction FlexBubbleDirectionType `json:"direction,omitempty"`
Header *BoxComponent `json:"header,omitempty"`
Hero *ImageComponent `json:"hero,omitempty"`
Body *BoxComponent `json:"body,omitempty"`
Footer *BoxComponent `json:"footer,omitempty"`
Styles *BubbleStyle `json:"styles,omitempty"`
}{
Type: FlexContainerTypeBubble,
Direction: c.Direction,
Header: c.Header,
Hero: c.Hero,
Body: c.Body,
Footer: c.Footer,
Styles: c.Styles,
})
}
|
go
|
func (c *BubbleContainer) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexContainerType `json:"type"`
Direction FlexBubbleDirectionType `json:"direction,omitempty"`
Header *BoxComponent `json:"header,omitempty"`
Hero *ImageComponent `json:"hero,omitempty"`
Body *BoxComponent `json:"body,omitempty"`
Footer *BoxComponent `json:"footer,omitempty"`
Styles *BubbleStyle `json:"styles,omitempty"`
}{
Type: FlexContainerTypeBubble,
Direction: c.Direction,
Header: c.Header,
Hero: c.Hero,
Body: c.Body,
Footer: c.Footer,
Styles: c.Styles,
})
}
|
[
"func",
"(",
"c",
"*",
"BubbleContainer",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexContainerType",
"`json:\"type\"`",
"\n",
"Direction",
"FlexBubbleDirectionType",
"`json:\"direction,omitempty\"`",
"\n",
"Header",
"*",
"BoxComponent",
"`json:\"header,omitempty\"`",
"\n",
"Hero",
"*",
"ImageComponent",
"`json:\"hero,omitempty\"`",
"\n",
"Body",
"*",
"BoxComponent",
"`json:\"body,omitempty\"`",
"\n",
"Footer",
"*",
"BoxComponent",
"`json:\"footer,omitempty\"`",
"\n",
"Styles",
"*",
"BubbleStyle",
"`json:\"styles,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexContainerTypeBubble",
",",
"Direction",
":",
"c",
".",
"Direction",
",",
"Header",
":",
"c",
".",
"Header",
",",
"Hero",
":",
"c",
".",
"Hero",
",",
"Body",
":",
"c",
".",
"Body",
",",
"Footer",
":",
"c",
".",
"Footer",
",",
"Styles",
":",
"c",
".",
"Styles",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of BubbleContainer
|
[
"MarshalJSON",
"method",
"of",
"BubbleContainer"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L263-L281
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *CarouselContainer) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexContainerType `json:"type"`
Contents []*BubbleContainer `json:"contents"`
}{
Type: FlexContainerTypeCarousel,
Contents: c.Contents,
})
}
|
go
|
func (c *CarouselContainer) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexContainerType `json:"type"`
Contents []*BubbleContainer `json:"contents"`
}{
Type: FlexContainerTypeCarousel,
Contents: c.Contents,
})
}
|
[
"func",
"(",
"c",
"*",
"CarouselContainer",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexContainerType",
"`json:\"type\"`",
"\n",
"Contents",
"[",
"]",
"*",
"BubbleContainer",
"`json:\"contents\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexContainerTypeCarousel",
",",
"Contents",
":",
"c",
".",
"Contents",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of CarouselContainer
|
[
"MarshalJSON",
"method",
"of",
"CarouselContainer"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L290-L298
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *BoxComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Layout FlexBoxLayoutType `json:"layout"`
Contents []FlexComponent `json:"contents"`
Flex *int `json:"flex,omitempty"`
Spacing FlexComponentSpacingType `json:"spacing,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
}{
Type: FlexComponentTypeBox,
Layout: c.Layout,
Contents: c.Contents,
Flex: c.Flex,
Spacing: c.Spacing,
Margin: c.Margin,
})
}
|
go
|
func (c *BoxComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Layout FlexBoxLayoutType `json:"layout"`
Contents []FlexComponent `json:"contents"`
Flex *int `json:"flex,omitempty"`
Spacing FlexComponentSpacingType `json:"spacing,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
}{
Type: FlexComponentTypeBox,
Layout: c.Layout,
Contents: c.Contents,
Flex: c.Flex,
Spacing: c.Spacing,
Margin: c.Margin,
})
}
|
[
"func",
"(",
"c",
"*",
"BoxComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"Layout",
"FlexBoxLayoutType",
"`json:\"layout\"`",
"\n",
"Contents",
"[",
"]",
"FlexComponent",
"`json:\"contents\"`",
"\n",
"Flex",
"*",
"int",
"`json:\"flex,omitempty\"`",
"\n",
"Spacing",
"FlexComponentSpacingType",
"`json:\"spacing,omitempty\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeBox",
",",
"Layout",
":",
"c",
".",
"Layout",
",",
"Contents",
":",
"c",
".",
"Contents",
",",
"Flex",
":",
"c",
".",
"Flex",
",",
"Spacing",
":",
"c",
".",
"Spacing",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of BoxComponent
|
[
"MarshalJSON",
"method",
"of",
"BoxComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L337-L353
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *ButtonComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Action TemplateAction `json:"action"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Height FlexButtonHeightType `json:"height,omitempty"`
Style FlexButtonStyleType `json:"style,omitempty"`
Color string `json:"color,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
}{
Type: FlexComponentTypeButton,
Action: c.Action,
Flex: c.Flex,
Margin: c.Margin,
Height: c.Height,
Style: c.Style,
Color: c.Color,
Gravity: c.Gravity,
})
}
|
go
|
func (c *ButtonComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Action TemplateAction `json:"action"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Height FlexButtonHeightType `json:"height,omitempty"`
Style FlexButtonStyleType `json:"style,omitempty"`
Color string `json:"color,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
}{
Type: FlexComponentTypeButton,
Action: c.Action,
Flex: c.Flex,
Margin: c.Margin,
Height: c.Height,
Style: c.Style,
Color: c.Color,
Gravity: c.Gravity,
})
}
|
[
"func",
"(",
"c",
"*",
"ButtonComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"Action",
"TemplateAction",
"`json:\"action\"`",
"\n",
"Flex",
"*",
"int",
"`json:\"flex,omitempty\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"Height",
"FlexButtonHeightType",
"`json:\"height,omitempty\"`",
"\n",
"Style",
"FlexButtonStyleType",
"`json:\"style,omitempty\"`",
"\n",
"Color",
"string",
"`json:\"color,omitempty\"`",
"\n",
"Gravity",
"FlexComponentGravityType",
"`json:\"gravity,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeButton",
",",
"Action",
":",
"c",
".",
"Action",
",",
"Flex",
":",
"c",
".",
"Flex",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"Height",
":",
"c",
".",
"Height",
",",
"Style",
":",
"c",
".",
"Style",
",",
"Color",
":",
"c",
".",
"Color",
",",
"Gravity",
":",
"c",
".",
"Gravity",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ButtonComponent
|
[
"MarshalJSON",
"method",
"of",
"ButtonComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L368-L388
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *FillerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
}{
Type: FlexComponentTypeFiller,
})
}
|
go
|
func (c *FillerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
}{
Type: FlexComponentTypeFiller,
})
}
|
[
"func",
"(",
"c",
"*",
"FillerComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeFiller",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of FillerComponent
|
[
"MarshalJSON",
"method",
"of",
"FillerComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L396-L402
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *IconComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexIconSizeType `json:"size,omitempty"`
AspectRatio FlexIconAspectRatioType `json:"aspectRatio,omitempty"`
}{
Type: FlexComponentTypeIcon,
URL: c.URL,
Margin: c.Margin,
Size: c.Size,
AspectRatio: c.AspectRatio,
})
}
|
go
|
func (c *IconComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexIconSizeType `json:"size,omitempty"`
AspectRatio FlexIconAspectRatioType `json:"aspectRatio,omitempty"`
}{
Type: FlexComponentTypeIcon,
URL: c.URL,
Margin: c.Margin,
Size: c.Size,
AspectRatio: c.AspectRatio,
})
}
|
[
"func",
"(",
"c",
"*",
"IconComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"URL",
"string",
"`json:\"url\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"Size",
"FlexIconSizeType",
"`json:\"size,omitempty\"`",
"\n",
"AspectRatio",
"FlexIconAspectRatioType",
"`json:\"aspectRatio,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeIcon",
",",
"URL",
":",
"c",
".",
"URL",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"Size",
":",
"c",
".",
"Size",
",",
"AspectRatio",
":",
"c",
".",
"AspectRatio",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of IconComponent
|
[
"MarshalJSON",
"method",
"of",
"IconComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L414-L428
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *ImageComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
Size FlexImageSizeType `json:"size,omitempty"`
AspectRatio FlexImageAspectRatioType `json:"aspectRatio,omitempty"`
AspectMode FlexImageAspectModeType `json:"aspectMode,omitempty"`
BackgroundColor string `json:"backgroundColor,omitempty"`
Action TemplateAction `json:"action,omitempty"`
}{
Type: FlexComponentTypeImage,
URL: c.URL,
Flex: c.Flex,
Margin: c.Margin,
Align: c.Align,
Gravity: c.Gravity,
Size: c.Size,
AspectRatio: c.AspectRatio,
AspectMode: c.AspectMode,
BackgroundColor: c.BackgroundColor,
Action: c.Action,
})
}
|
go
|
func (c *ImageComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
Size FlexImageSizeType `json:"size,omitempty"`
AspectRatio FlexImageAspectRatioType `json:"aspectRatio,omitempty"`
AspectMode FlexImageAspectModeType `json:"aspectMode,omitempty"`
BackgroundColor string `json:"backgroundColor,omitempty"`
Action TemplateAction `json:"action,omitempty"`
}{
Type: FlexComponentTypeImage,
URL: c.URL,
Flex: c.Flex,
Margin: c.Margin,
Align: c.Align,
Gravity: c.Gravity,
Size: c.Size,
AspectRatio: c.AspectRatio,
AspectMode: c.AspectMode,
BackgroundColor: c.BackgroundColor,
Action: c.Action,
})
}
|
[
"func",
"(",
"c",
"*",
"ImageComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"URL",
"string",
"`json:\"url\"`",
"\n",
"Flex",
"*",
"int",
"`json:\"flex,omitempty\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"Align",
"FlexComponentAlignType",
"`json:\"align,omitempty\"`",
"\n",
"Gravity",
"FlexComponentGravityType",
"`json:\"gravity,omitempty\"`",
"\n",
"Size",
"FlexImageSizeType",
"`json:\"size,omitempty\"`",
"\n",
"AspectRatio",
"FlexImageAspectRatioType",
"`json:\"aspectRatio,omitempty\"`",
"\n",
"AspectMode",
"FlexImageAspectModeType",
"`json:\"aspectMode,omitempty\"`",
"\n",
"BackgroundColor",
"string",
"`json:\"backgroundColor,omitempty\"`",
"\n",
"Action",
"TemplateAction",
"`json:\"action,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeImage",
",",
"URL",
":",
"c",
".",
"URL",
",",
"Flex",
":",
"c",
".",
"Flex",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"Align",
":",
"c",
".",
"Align",
",",
"Gravity",
":",
"c",
".",
"Gravity",
",",
"Size",
":",
"c",
".",
"Size",
",",
"AspectRatio",
":",
"c",
".",
"AspectRatio",
",",
"AspectMode",
":",
"c",
".",
"AspectMode",
",",
"BackgroundColor",
":",
"c",
".",
"BackgroundColor",
",",
"Action",
":",
"c",
".",
"Action",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ImageComponent
|
[
"MarshalJSON",
"method",
"of",
"ImageComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L446-L472
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *SeparatorComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Color string `json:"color,omitempty"`
}{
Type: FlexComponentTypeSeparator,
Margin: c.Margin,
Color: c.Color,
})
}
|
go
|
func (c *SeparatorComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Color string `json:"color,omitempty"`
}{
Type: FlexComponentTypeSeparator,
Margin: c.Margin,
Color: c.Color,
})
}
|
[
"func",
"(",
"c",
"*",
"SeparatorComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"Color",
"string",
"`json:\"color,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeSeparator",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"Color",
":",
"c",
".",
"Color",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of SeparatorComponent
|
[
"MarshalJSON",
"method",
"of",
"SeparatorComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L482-L492
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *SpacerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Size FlexSpacerSizeType `json:"size,omitempty"`
}{
Type: FlexComponentTypeSpacer,
Size: c.Size,
})
}
|
go
|
func (c *SpacerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Size FlexSpacerSizeType `json:"size,omitempty"`
}{
Type: FlexComponentTypeSpacer,
Size: c.Size,
})
}
|
[
"func",
"(",
"c",
"*",
"SpacerComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"Size",
"FlexSpacerSizeType",
"`json:\"size,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeSpacer",
",",
"Size",
":",
"c",
".",
"Size",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of SpacerComponent
|
[
"MarshalJSON",
"method",
"of",
"SpacerComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L501-L509
|
train
|
line/line-bot-sdk-go
|
linebot/flex.go
|
MarshalJSON
|
func (c *TextComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Text string `json:"text"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexTextSizeType `json:"size,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
Wrap bool `json:"wrap,omitempty"`
Weight FlexTextWeightType `json:"weight,omitempty"`
Color string `json:"color,omitempty"`
Action TemplateAction `json:"action,omitempty"`
}{
Type: FlexComponentTypeText,
Text: c.Text,
Flex: c.Flex,
Margin: c.Margin,
Size: c.Size,
Align: c.Align,
Gravity: c.Gravity,
Wrap: c.Wrap,
Weight: c.Weight,
Color: c.Color,
Action: c.Action,
})
}
|
go
|
func (c *TextComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Text string `json:"text"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexTextSizeType `json:"size,omitempty"`
Align FlexComponentAlignType `json:"align,omitempty"`
Gravity FlexComponentGravityType `json:"gravity,omitempty"`
Wrap bool `json:"wrap,omitempty"`
Weight FlexTextWeightType `json:"weight,omitempty"`
Color string `json:"color,omitempty"`
Action TemplateAction `json:"action,omitempty"`
}{
Type: FlexComponentTypeText,
Text: c.Text,
Flex: c.Flex,
Margin: c.Margin,
Size: c.Size,
Align: c.Align,
Gravity: c.Gravity,
Wrap: c.Wrap,
Weight: c.Weight,
Color: c.Color,
Action: c.Action,
})
}
|
[
"func",
"(",
"c",
"*",
"TextComponent",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"FlexComponentType",
"`json:\"type\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"Flex",
"*",
"int",
"`json:\"flex,omitempty\"`",
"\n",
"Margin",
"FlexComponentMarginType",
"`json:\"margin,omitempty\"`",
"\n",
"Size",
"FlexTextSizeType",
"`json:\"size,omitempty\"`",
"\n",
"Align",
"FlexComponentAlignType",
"`json:\"align,omitempty\"`",
"\n",
"Gravity",
"FlexComponentGravityType",
"`json:\"gravity,omitempty\"`",
"\n",
"Wrap",
"bool",
"`json:\"wrap,omitempty\"`",
"\n",
"Weight",
"FlexTextWeightType",
"`json:\"weight,omitempty\"`",
"\n",
"Color",
"string",
"`json:\"color,omitempty\"`",
"\n",
"Action",
"TemplateAction",
"`json:\"action,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"FlexComponentTypeText",
",",
"Text",
":",
"c",
".",
"Text",
",",
"Flex",
":",
"c",
".",
"Flex",
",",
"Margin",
":",
"c",
".",
"Margin",
",",
"Size",
":",
"c",
".",
"Size",
",",
"Align",
":",
"c",
".",
"Align",
",",
"Gravity",
":",
"c",
".",
"Gravity",
",",
"Wrap",
":",
"c",
".",
"Wrap",
",",
"Weight",
":",
"c",
".",
"Weight",
",",
"Color",
":",
"c",
".",
"Color",
",",
"Action",
":",
"c",
".",
"Action",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of TextComponent
|
[
"MarshalJSON",
"method",
"of",
"TextComponent"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/flex.go#L527-L553
|
train
|
line/line-bot-sdk-go
|
linebot/event.go
|
MarshalJSON
|
func (e *Event) MarshalJSON() ([]byte, error) {
raw := rawEvent{
ReplyToken: e.ReplyToken,
Type: e.Type,
Timestamp: e.Timestamp.Unix()*millisecPerSec + int64(e.Timestamp.Nanosecond())/int64(time.Millisecond),
Source: e.Source,
Postback: e.Postback,
}
if e.Beacon != nil {
raw.Beacon = &rawBeaconEvent{
Hwid: e.Beacon.Hwid,
Type: e.Beacon.Type,
DM: hex.EncodeToString(e.Beacon.DeviceMessage),
}
}
if e.AccountLink != nil {
raw.AccountLink = &rawAccountLinkEvent{
Result: e.AccountLink.Result,
Nonce: e.AccountLink.Nonce,
}
}
switch e.Type {
case EventTypeMemberJoined:
raw.Joined = &rawMemberEvent{
Members: e.Members,
}
case EventTypeMemberLeft:
raw.Left = &rawMemberEvent{
Members: e.Members,
}
case EventTypeThings:
raw.Things = &Things{
DeviceID: e.Things.DeviceID,
Type: e.Things.Type,
}
}
switch m := e.Message.(type) {
case *TextMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeText,
ID: m.ID,
Text: m.Text,
}
case *ImageMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeImage,
ID: m.ID,
}
case *VideoMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeVideo,
ID: m.ID,
}
case *AudioMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeAudio,
ID: m.ID,
Duration: m.Duration,
}
case *FileMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeFile,
ID: m.ID,
FileName: m.FileName,
FileSize: m.FileSize,
}
case *LocationMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeLocation,
ID: m.ID,
Title: m.Title,
Address: m.Address,
Latitude: m.Latitude,
Longitude: m.Longitude,
}
case *StickerMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeSticker,
ID: m.ID,
PackageID: m.PackageID,
StickerID: m.StickerID,
}
}
return json.Marshal(&raw)
}
|
go
|
func (e *Event) MarshalJSON() ([]byte, error) {
raw := rawEvent{
ReplyToken: e.ReplyToken,
Type: e.Type,
Timestamp: e.Timestamp.Unix()*millisecPerSec + int64(e.Timestamp.Nanosecond())/int64(time.Millisecond),
Source: e.Source,
Postback: e.Postback,
}
if e.Beacon != nil {
raw.Beacon = &rawBeaconEvent{
Hwid: e.Beacon.Hwid,
Type: e.Beacon.Type,
DM: hex.EncodeToString(e.Beacon.DeviceMessage),
}
}
if e.AccountLink != nil {
raw.AccountLink = &rawAccountLinkEvent{
Result: e.AccountLink.Result,
Nonce: e.AccountLink.Nonce,
}
}
switch e.Type {
case EventTypeMemberJoined:
raw.Joined = &rawMemberEvent{
Members: e.Members,
}
case EventTypeMemberLeft:
raw.Left = &rawMemberEvent{
Members: e.Members,
}
case EventTypeThings:
raw.Things = &Things{
DeviceID: e.Things.DeviceID,
Type: e.Things.Type,
}
}
switch m := e.Message.(type) {
case *TextMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeText,
ID: m.ID,
Text: m.Text,
}
case *ImageMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeImage,
ID: m.ID,
}
case *VideoMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeVideo,
ID: m.ID,
}
case *AudioMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeAudio,
ID: m.ID,
Duration: m.Duration,
}
case *FileMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeFile,
ID: m.ID,
FileName: m.FileName,
FileSize: m.FileSize,
}
case *LocationMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeLocation,
ID: m.ID,
Title: m.Title,
Address: m.Address,
Latitude: m.Latitude,
Longitude: m.Longitude,
}
case *StickerMessage:
raw.Message = &rawEventMessage{
Type: MessageTypeSticker,
ID: m.ID,
PackageID: m.PackageID,
StickerID: m.StickerID,
}
}
return json.Marshal(&raw)
}
|
[
"func",
"(",
"e",
"*",
"Event",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"raw",
":=",
"rawEvent",
"{",
"ReplyToken",
":",
"e",
".",
"ReplyToken",
",",
"Type",
":",
"e",
".",
"Type",
",",
"Timestamp",
":",
"e",
".",
"Timestamp",
".",
"Unix",
"(",
")",
"*",
"millisecPerSec",
"+",
"int64",
"(",
"e",
".",
"Timestamp",
".",
"Nanosecond",
"(",
")",
")",
"/",
"int64",
"(",
"time",
".",
"Millisecond",
")",
",",
"Source",
":",
"e",
".",
"Source",
",",
"Postback",
":",
"e",
".",
"Postback",
",",
"}",
"\n",
"if",
"e",
".",
"Beacon",
"!=",
"nil",
"{",
"raw",
".",
"Beacon",
"=",
"&",
"rawBeaconEvent",
"{",
"Hwid",
":",
"e",
".",
"Beacon",
".",
"Hwid",
",",
"Type",
":",
"e",
".",
"Beacon",
".",
"Type",
",",
"DM",
":",
"hex",
".",
"EncodeToString",
"(",
"e",
".",
"Beacon",
".",
"DeviceMessage",
")",
",",
"}",
"\n",
"}",
"\n",
"if",
"e",
".",
"AccountLink",
"!=",
"nil",
"{",
"raw",
".",
"AccountLink",
"=",
"&",
"rawAccountLinkEvent",
"{",
"Result",
":",
"e",
".",
"AccountLink",
".",
"Result",
",",
"Nonce",
":",
"e",
".",
"AccountLink",
".",
"Nonce",
",",
"}",
"\n",
"}",
"\n\n",
"switch",
"e",
".",
"Type",
"{",
"case",
"EventTypeMemberJoined",
":",
"raw",
".",
"Joined",
"=",
"&",
"rawMemberEvent",
"{",
"Members",
":",
"e",
".",
"Members",
",",
"}",
"\n",
"case",
"EventTypeMemberLeft",
":",
"raw",
".",
"Left",
"=",
"&",
"rawMemberEvent",
"{",
"Members",
":",
"e",
".",
"Members",
",",
"}",
"\n",
"case",
"EventTypeThings",
":",
"raw",
".",
"Things",
"=",
"&",
"Things",
"{",
"DeviceID",
":",
"e",
".",
"Things",
".",
"DeviceID",
",",
"Type",
":",
"e",
".",
"Things",
".",
"Type",
",",
"}",
"\n",
"}",
"\n\n",
"switch",
"m",
":=",
"e",
".",
"Message",
".",
"(",
"type",
")",
"{",
"case",
"*",
"TextMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeText",
",",
"ID",
":",
"m",
".",
"ID",
",",
"Text",
":",
"m",
".",
"Text",
",",
"}",
"\n",
"case",
"*",
"ImageMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeImage",
",",
"ID",
":",
"m",
".",
"ID",
",",
"}",
"\n",
"case",
"*",
"VideoMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeVideo",
",",
"ID",
":",
"m",
".",
"ID",
",",
"}",
"\n",
"case",
"*",
"AudioMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeAudio",
",",
"ID",
":",
"m",
".",
"ID",
",",
"Duration",
":",
"m",
".",
"Duration",
",",
"}",
"\n",
"case",
"*",
"FileMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeFile",
",",
"ID",
":",
"m",
".",
"ID",
",",
"FileName",
":",
"m",
".",
"FileName",
",",
"FileSize",
":",
"m",
".",
"FileSize",
",",
"}",
"\n",
"case",
"*",
"LocationMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeLocation",
",",
"ID",
":",
"m",
".",
"ID",
",",
"Title",
":",
"m",
".",
"Title",
",",
"Address",
":",
"m",
".",
"Address",
",",
"Latitude",
":",
"m",
".",
"Latitude",
",",
"Longitude",
":",
"m",
".",
"Longitude",
",",
"}",
"\n",
"case",
"*",
"StickerMessage",
":",
"raw",
".",
"Message",
"=",
"&",
"rawEventMessage",
"{",
"Type",
":",
"MessageTypeSticker",
",",
"ID",
":",
"m",
".",
"ID",
",",
"PackageID",
":",
"m",
".",
"PackageID",
",",
"StickerID",
":",
"m",
".",
"StickerID",
",",
"}",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"&",
"raw",
")",
"\n",
"}"
] |
// MarshalJSON method of Event
|
[
"MarshalJSON",
"method",
"of",
"Event"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/event.go#L181-L267
|
train
|
line/line-bot-sdk-go
|
linebot/event.go
|
UnmarshalJSON
|
func (e *Event) UnmarshalJSON(body []byte) (err error) {
rawEvent := rawEvent{}
if err = json.Unmarshal(body, &rawEvent); err != nil {
return
}
e.ReplyToken = rawEvent.ReplyToken
e.Type = rawEvent.Type
e.Timestamp = time.Unix(rawEvent.Timestamp/millisecPerSec, (rawEvent.Timestamp%millisecPerSec)*nanosecPerMillisec).UTC()
e.Source = rawEvent.Source
switch rawEvent.Type {
case EventTypeMessage:
switch rawEvent.Message.Type {
case MessageTypeText:
e.Message = &TextMessage{
ID: rawEvent.Message.ID,
Text: rawEvent.Message.Text,
}
case MessageTypeImage:
e.Message = &ImageMessage{
ID: rawEvent.Message.ID,
}
case MessageTypeVideo:
e.Message = &VideoMessage{
ID: rawEvent.Message.ID,
}
case MessageTypeAudio:
e.Message = &AudioMessage{
ID: rawEvent.Message.ID,
Duration: rawEvent.Message.Duration,
}
case MessageTypeFile:
e.Message = &FileMessage{
ID: rawEvent.Message.ID,
FileName: rawEvent.Message.FileName,
FileSize: rawEvent.Message.FileSize,
}
case MessageTypeLocation:
e.Message = &LocationMessage{
ID: rawEvent.Message.ID,
Title: rawEvent.Message.Title,
Address: rawEvent.Message.Address,
Latitude: rawEvent.Message.Latitude,
Longitude: rawEvent.Message.Longitude,
}
case MessageTypeSticker:
e.Message = &StickerMessage{
ID: rawEvent.Message.ID,
PackageID: rawEvent.Message.PackageID,
StickerID: rawEvent.Message.StickerID,
}
}
case EventTypePostback:
e.Postback = rawEvent.Postback
case EventTypeBeacon:
var deviceMessage []byte
deviceMessage, err = hex.DecodeString(rawEvent.Beacon.DM)
if err != nil {
return
}
e.Beacon = &Beacon{
Hwid: rawEvent.Beacon.Hwid,
Type: rawEvent.Beacon.Type,
DeviceMessage: deviceMessage,
}
case EventTypeAccountLink:
e.AccountLink = &AccountLink{
Result: rawEvent.AccountLink.Result,
Nonce: rawEvent.AccountLink.Nonce,
}
case EventTypeMemberJoined:
e.Members = rawEvent.Joined.Members
case EventTypeMemberLeft:
e.Members = rawEvent.Left.Members
case EventTypeThings:
e.Things = new(Things)
e.Things.Type = rawEvent.Things.Type
e.Things.DeviceID = rawEvent.Things.DeviceID
}
return
}
|
go
|
func (e *Event) UnmarshalJSON(body []byte) (err error) {
rawEvent := rawEvent{}
if err = json.Unmarshal(body, &rawEvent); err != nil {
return
}
e.ReplyToken = rawEvent.ReplyToken
e.Type = rawEvent.Type
e.Timestamp = time.Unix(rawEvent.Timestamp/millisecPerSec, (rawEvent.Timestamp%millisecPerSec)*nanosecPerMillisec).UTC()
e.Source = rawEvent.Source
switch rawEvent.Type {
case EventTypeMessage:
switch rawEvent.Message.Type {
case MessageTypeText:
e.Message = &TextMessage{
ID: rawEvent.Message.ID,
Text: rawEvent.Message.Text,
}
case MessageTypeImage:
e.Message = &ImageMessage{
ID: rawEvent.Message.ID,
}
case MessageTypeVideo:
e.Message = &VideoMessage{
ID: rawEvent.Message.ID,
}
case MessageTypeAudio:
e.Message = &AudioMessage{
ID: rawEvent.Message.ID,
Duration: rawEvent.Message.Duration,
}
case MessageTypeFile:
e.Message = &FileMessage{
ID: rawEvent.Message.ID,
FileName: rawEvent.Message.FileName,
FileSize: rawEvent.Message.FileSize,
}
case MessageTypeLocation:
e.Message = &LocationMessage{
ID: rawEvent.Message.ID,
Title: rawEvent.Message.Title,
Address: rawEvent.Message.Address,
Latitude: rawEvent.Message.Latitude,
Longitude: rawEvent.Message.Longitude,
}
case MessageTypeSticker:
e.Message = &StickerMessage{
ID: rawEvent.Message.ID,
PackageID: rawEvent.Message.PackageID,
StickerID: rawEvent.Message.StickerID,
}
}
case EventTypePostback:
e.Postback = rawEvent.Postback
case EventTypeBeacon:
var deviceMessage []byte
deviceMessage, err = hex.DecodeString(rawEvent.Beacon.DM)
if err != nil {
return
}
e.Beacon = &Beacon{
Hwid: rawEvent.Beacon.Hwid,
Type: rawEvent.Beacon.Type,
DeviceMessage: deviceMessage,
}
case EventTypeAccountLink:
e.AccountLink = &AccountLink{
Result: rawEvent.AccountLink.Result,
Nonce: rawEvent.AccountLink.Nonce,
}
case EventTypeMemberJoined:
e.Members = rawEvent.Joined.Members
case EventTypeMemberLeft:
e.Members = rawEvent.Left.Members
case EventTypeThings:
e.Things = new(Things)
e.Things.Type = rawEvent.Things.Type
e.Things.DeviceID = rawEvent.Things.DeviceID
}
return
}
|
[
"func",
"(",
"e",
"*",
"Event",
")",
"UnmarshalJSON",
"(",
"body",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"rawEvent",
":=",
"rawEvent",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"rawEvent",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"e",
".",
"ReplyToken",
"=",
"rawEvent",
".",
"ReplyToken",
"\n",
"e",
".",
"Type",
"=",
"rawEvent",
".",
"Type",
"\n",
"e",
".",
"Timestamp",
"=",
"time",
".",
"Unix",
"(",
"rawEvent",
".",
"Timestamp",
"/",
"millisecPerSec",
",",
"(",
"rawEvent",
".",
"Timestamp",
"%",
"millisecPerSec",
")",
"*",
"nanosecPerMillisec",
")",
".",
"UTC",
"(",
")",
"\n",
"e",
".",
"Source",
"=",
"rawEvent",
".",
"Source",
"\n\n",
"switch",
"rawEvent",
".",
"Type",
"{",
"case",
"EventTypeMessage",
":",
"switch",
"rawEvent",
".",
"Message",
".",
"Type",
"{",
"case",
"MessageTypeText",
":",
"e",
".",
"Message",
"=",
"&",
"TextMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"Text",
":",
"rawEvent",
".",
"Message",
".",
"Text",
",",
"}",
"\n",
"case",
"MessageTypeImage",
":",
"e",
".",
"Message",
"=",
"&",
"ImageMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"}",
"\n",
"case",
"MessageTypeVideo",
":",
"e",
".",
"Message",
"=",
"&",
"VideoMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"}",
"\n",
"case",
"MessageTypeAudio",
":",
"e",
".",
"Message",
"=",
"&",
"AudioMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"Duration",
":",
"rawEvent",
".",
"Message",
".",
"Duration",
",",
"}",
"\n",
"case",
"MessageTypeFile",
":",
"e",
".",
"Message",
"=",
"&",
"FileMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"FileName",
":",
"rawEvent",
".",
"Message",
".",
"FileName",
",",
"FileSize",
":",
"rawEvent",
".",
"Message",
".",
"FileSize",
",",
"}",
"\n",
"case",
"MessageTypeLocation",
":",
"e",
".",
"Message",
"=",
"&",
"LocationMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"Title",
":",
"rawEvent",
".",
"Message",
".",
"Title",
",",
"Address",
":",
"rawEvent",
".",
"Message",
".",
"Address",
",",
"Latitude",
":",
"rawEvent",
".",
"Message",
".",
"Latitude",
",",
"Longitude",
":",
"rawEvent",
".",
"Message",
".",
"Longitude",
",",
"}",
"\n",
"case",
"MessageTypeSticker",
":",
"e",
".",
"Message",
"=",
"&",
"StickerMessage",
"{",
"ID",
":",
"rawEvent",
".",
"Message",
".",
"ID",
",",
"PackageID",
":",
"rawEvent",
".",
"Message",
".",
"PackageID",
",",
"StickerID",
":",
"rawEvent",
".",
"Message",
".",
"StickerID",
",",
"}",
"\n",
"}",
"\n",
"case",
"EventTypePostback",
":",
"e",
".",
"Postback",
"=",
"rawEvent",
".",
"Postback",
"\n",
"case",
"EventTypeBeacon",
":",
"var",
"deviceMessage",
"[",
"]",
"byte",
"\n",
"deviceMessage",
",",
"err",
"=",
"hex",
".",
"DecodeString",
"(",
"rawEvent",
".",
"Beacon",
".",
"DM",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"e",
".",
"Beacon",
"=",
"&",
"Beacon",
"{",
"Hwid",
":",
"rawEvent",
".",
"Beacon",
".",
"Hwid",
",",
"Type",
":",
"rawEvent",
".",
"Beacon",
".",
"Type",
",",
"DeviceMessage",
":",
"deviceMessage",
",",
"}",
"\n",
"case",
"EventTypeAccountLink",
":",
"e",
".",
"AccountLink",
"=",
"&",
"AccountLink",
"{",
"Result",
":",
"rawEvent",
".",
"AccountLink",
".",
"Result",
",",
"Nonce",
":",
"rawEvent",
".",
"AccountLink",
".",
"Nonce",
",",
"}",
"\n",
"case",
"EventTypeMemberJoined",
":",
"e",
".",
"Members",
"=",
"rawEvent",
".",
"Joined",
".",
"Members",
"\n",
"case",
"EventTypeMemberLeft",
":",
"e",
".",
"Members",
"=",
"rawEvent",
".",
"Left",
".",
"Members",
"\n",
"case",
"EventTypeThings",
":",
"e",
".",
"Things",
"=",
"new",
"(",
"Things",
")",
"\n",
"e",
".",
"Things",
".",
"Type",
"=",
"rawEvent",
".",
"Things",
".",
"Type",
"\n",
"e",
".",
"Things",
".",
"DeviceID",
"=",
"rawEvent",
".",
"Things",
".",
"DeviceID",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// UnmarshalJSON method of Event
|
[
"UnmarshalJSON",
"method",
"of",
"Event"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/event.go#L270-L351
|
train
|
line/line-bot-sdk-go
|
linebot/quick_reply.go
|
MarshalJSON
|
func (b *QuickReplyButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
ImageURL string `json:"imageUrl,omitempty"`
Action QuickReplyAction `json:"action"`
}{
Type: "action",
ImageURL: b.ImageURL,
Action: b.Action,
})
}
|
go
|
func (b *QuickReplyButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
ImageURL string `json:"imageUrl,omitempty"`
Action QuickReplyAction `json:"action"`
}{
Type: "action",
ImageURL: b.ImageURL,
Action: b.Action,
})
}
|
[
"func",
"(",
"b",
"*",
"QuickReplyButton",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"ImageURL",
"string",
"`json:\"imageUrl,omitempty\"`",
"\n",
"Action",
"QuickReplyAction",
"`json:\"action\"`",
"\n",
"}",
"{",
"Type",
":",
"\"",
"\"",
",",
"ImageURL",
":",
"b",
".",
"ImageURL",
",",
"Action",
":",
"b",
".",
"Action",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of QuickReplyButton
|
[
"MarshalJSON",
"method",
"of",
"QuickReplyButton"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/quick_reply.go#L40-L50
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *URIAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
URI string `json:"uri"`
AltURI *URIActionAltURI `json:"altUri,omitempty"`
}{
Type: ActionTypeURI,
Label: a.Label,
URI: a.URI,
AltURI: a.AltURI,
})
}
|
go
|
func (a *URIAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
URI string `json:"uri"`
AltURI *URIActionAltURI `json:"altUri,omitempty"`
}{
Type: ActionTypeURI,
Label: a.Label,
URI: a.URI,
AltURI: a.AltURI,
})
}
|
[
"func",
"(",
"a",
"*",
"URIAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label,omitempty\"`",
"\n",
"URI",
"string",
"`json:\"uri\"`",
"\n",
"AltURI",
"*",
"URIActionAltURI",
"`json:\"altUri,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeURI",
",",
"Label",
":",
"a",
".",
"Label",
",",
"URI",
":",
"a",
".",
"URI",
",",
"AltURI",
":",
"a",
".",
"AltURI",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of URIAction
|
[
"MarshalJSON",
"method",
"of",
"URIAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L63-L75
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *MessageAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Text string `json:"text"`
}{
Type: ActionTypeMessage,
Label: a.Label,
Text: a.Text,
})
}
|
go
|
func (a *MessageAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Text string `json:"text"`
}{
Type: ActionTypeMessage,
Label: a.Label,
Text: a.Text,
})
}
|
[
"func",
"(",
"a",
"*",
"MessageAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label,omitempty\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeMessage",
",",
"Label",
":",
"a",
".",
"Label",
",",
"Text",
":",
"a",
".",
"Text",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of MessageAction
|
[
"MarshalJSON",
"method",
"of",
"MessageAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L84-L94
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *PostbackAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Text string `json:"text,omitempty"`
DisplayText string `json:"displayText,omitempty"`
}{
Type: ActionTypePostback,
Label: a.Label,
Data: a.Data,
Text: a.Text,
DisplayText: a.DisplayText,
})
}
|
go
|
func (a *PostbackAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Text string `json:"text,omitempty"`
DisplayText string `json:"displayText,omitempty"`
}{
Type: ActionTypePostback,
Label: a.Label,
Data: a.Data,
Text: a.Text,
DisplayText: a.DisplayText,
})
}
|
[
"func",
"(",
"a",
"*",
"PostbackAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label,omitempty\"`",
"\n",
"Data",
"string",
"`json:\"data\"`",
"\n",
"Text",
"string",
"`json:\"text,omitempty\"`",
"\n",
"DisplayText",
"string",
"`json:\"displayText,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypePostback",
",",
"Label",
":",
"a",
".",
"Label",
",",
"Data",
":",
"a",
".",
"Data",
",",
"Text",
":",
"a",
".",
"Text",
",",
"DisplayText",
":",
"a",
".",
"DisplayText",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of PostbackAction
|
[
"MarshalJSON",
"method",
"of",
"PostbackAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L105-L119
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *DatetimePickerAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Mode string `json:"mode"`
Initial string `json:"initial,omitempty"`
Max string `json:"max,omitempty"`
Min string `json:"min,omitempty"`
}{
Type: ActionTypeDatetimePicker,
Label: a.Label,
Data: a.Data,
Mode: a.Mode,
Initial: a.Initial,
Max: a.Max,
Min: a.Min,
})
}
|
go
|
func (a *DatetimePickerAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Mode string `json:"mode"`
Initial string `json:"initial,omitempty"`
Max string `json:"max,omitempty"`
Min string `json:"min,omitempty"`
}{
Type: ActionTypeDatetimePicker,
Label: a.Label,
Data: a.Data,
Mode: a.Mode,
Initial: a.Initial,
Max: a.Max,
Min: a.Min,
})
}
|
[
"func",
"(",
"a",
"*",
"DatetimePickerAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label,omitempty\"`",
"\n",
"Data",
"string",
"`json:\"data\"`",
"\n",
"Mode",
"string",
"`json:\"mode\"`",
"\n",
"Initial",
"string",
"`json:\"initial,omitempty\"`",
"\n",
"Max",
"string",
"`json:\"max,omitempty\"`",
"\n",
"Min",
"string",
"`json:\"min,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeDatetimePicker",
",",
"Label",
":",
"a",
".",
"Label",
",",
"Data",
":",
"a",
".",
"Data",
",",
"Mode",
":",
"a",
".",
"Mode",
",",
"Initial",
":",
"a",
".",
"Initial",
",",
"Max",
":",
"a",
".",
"Max",
",",
"Min",
":",
"a",
".",
"Min",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of DatetimePickerAction
|
[
"MarshalJSON",
"method",
"of",
"DatetimePickerAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L132-L150
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *CameraAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCamera,
Label: a.Label,
})
}
|
go
|
func (a *CameraAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCamera,
Label: a.Label,
})
}
|
[
"func",
"(",
"a",
"*",
"CameraAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeCamera",
",",
"Label",
":",
"a",
".",
"Label",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of CameraAction
|
[
"MarshalJSON",
"method",
"of",
"CameraAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L158-L166
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *CameraRollAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCameraRoll,
Label: a.Label,
})
}
|
go
|
func (a *CameraRollAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCameraRoll,
Label: a.Label,
})
}
|
[
"func",
"(",
"a",
"*",
"CameraRollAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeCameraRoll",
",",
"Label",
":",
"a",
".",
"Label",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of CameraRollAction
|
[
"MarshalJSON",
"method",
"of",
"CameraRollAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L174-L182
|
train
|
line/line-bot-sdk-go
|
linebot/actions.go
|
MarshalJSON
|
func (a *LocationAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeLocation,
Label: a.Label,
})
}
|
go
|
func (a *LocationAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeLocation,
Label: a.Label,
})
}
|
[
"func",
"(",
"a",
"*",
"LocationAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"ActionType",
"`json:\"type\"`",
"\n",
"Label",
"string",
"`json:\"label\"`",
"\n",
"}",
"{",
"Type",
":",
"ActionTypeLocation",
",",
"Label",
":",
"a",
".",
"Label",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of LocationAction
|
[
"MarshalJSON",
"method",
"of",
"LocationAction"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/actions.go#L190-L198
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *TextMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Text string `json:"text"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeText,
Text: m.Text,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *TextMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Text string `json:"text"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeText,
Text: m.Text,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"TextMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"Text",
"string",
"`json:\"text\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeText",
",",
"Text",
":",
"m",
".",
"Text",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of TextMessage
|
[
"MarshalJSON",
"method",
"of",
"TextMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L58-L68
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *TextMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *TextMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"TextMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of TextMessage
|
[
"WithQuickReplies",
"method",
"of",
"TextMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L71-L74
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *ImageMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeImage,
OriginalContentURL: m.OriginalContentURL,
PreviewImageURL: m.PreviewImageURL,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *ImageMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeImage,
OriginalContentURL: m.OriginalContentURL,
PreviewImageURL: m.PreviewImageURL,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"ImageMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"OriginalContentURL",
"string",
"`json:\"originalContentUrl\"`",
"\n",
"PreviewImageURL",
"string",
"`json:\"previewImageUrl\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeImage",
",",
"OriginalContentURL",
":",
"m",
".",
"OriginalContentURL",
",",
"PreviewImageURL",
":",
"m",
".",
"PreviewImageURL",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ImageMessage
|
[
"MarshalJSON",
"method",
"of",
"ImageMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L86-L98
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *ImageMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *ImageMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"ImageMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of ImageMessage
|
[
"WithQuickReplies",
"method",
"of",
"ImageMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L101-L104
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *VideoMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeVideo,
OriginalContentURL: m.OriginalContentURL,
PreviewImageURL: m.PreviewImageURL,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *VideoMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeVideo,
OriginalContentURL: m.OriginalContentURL,
PreviewImageURL: m.PreviewImageURL,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"VideoMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"OriginalContentURL",
"string",
"`json:\"originalContentUrl\"`",
"\n",
"PreviewImageURL",
"string",
"`json:\"previewImageUrl\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeVideo",
",",
"OriginalContentURL",
":",
"m",
".",
"OriginalContentURL",
",",
"PreviewImageURL",
":",
"m",
".",
"PreviewImageURL",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of VideoMessage
|
[
"MarshalJSON",
"method",
"of",
"VideoMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L116-L128
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *VideoMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *VideoMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"VideoMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of VideoMessage
|
[
"WithQuickReplies",
"method",
"of",
"VideoMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L131-L134
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *AudioMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
Duration int `json:"duration"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeAudio,
OriginalContentURL: m.OriginalContentURL,
Duration: m.Duration,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *AudioMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
Duration int `json:"duration"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeAudio,
OriginalContentURL: m.OriginalContentURL,
Duration: m.Duration,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"AudioMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"OriginalContentURL",
"string",
"`json:\"originalContentUrl\"`",
"\n",
"Duration",
"int",
"`json:\"duration\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeAudio",
",",
"OriginalContentURL",
":",
"m",
".",
"OriginalContentURL",
",",
"Duration",
":",
"m",
".",
"Duration",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of AudioMessage
|
[
"MarshalJSON",
"method",
"of",
"AudioMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L146-L158
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *AudioMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *AudioMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"AudioMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of AudioMessage
|
[
"WithQuickReplies",
"method",
"of",
"AudioMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L161-L164
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *LocationMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Title string `json:"title"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeLocation,
Title: m.Title,
Address: m.Address,
Latitude: m.Latitude,
Longitude: m.Longitude,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *LocationMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Title string `json:"title"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeLocation,
Title: m.Title,
Address: m.Address,
Latitude: m.Latitude,
Longitude: m.Longitude,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"LocationMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"Title",
"string",
"`json:\"title\"`",
"\n",
"Address",
"string",
"`json:\"address\"`",
"\n",
"Latitude",
"float64",
"`json:\"latitude\"`",
"\n",
"Longitude",
"float64",
"`json:\"longitude\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeLocation",
",",
"Title",
":",
"m",
".",
"Title",
",",
"Address",
":",
"m",
".",
"Address",
",",
"Latitude",
":",
"m",
".",
"Latitude",
",",
"Longitude",
":",
"m",
".",
"Longitude",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of LocationMessage
|
[
"MarshalJSON",
"method",
"of",
"LocationMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L185-L201
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *LocationMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *LocationMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"LocationMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of LocationMessage
|
[
"WithQuickReplies",
"method",
"of",
"LocationMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L204-L207
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *StickerMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
PackageID string `json:"packageId"`
StickerID string `json:"stickerId"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeSticker,
PackageID: m.PackageID,
StickerID: m.StickerID,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *StickerMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
PackageID string `json:"packageId"`
StickerID string `json:"stickerId"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeSticker,
PackageID: m.PackageID,
StickerID: m.StickerID,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"StickerMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"PackageID",
"string",
"`json:\"packageId\"`",
"\n",
"StickerID",
"string",
"`json:\"stickerId\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeSticker",
",",
"PackageID",
":",
"m",
".",
"PackageID",
",",
"StickerID",
":",
"m",
".",
"StickerID",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of StickerMessage
|
[
"MarshalJSON",
"method",
"of",
"StickerMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L219-L231
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *StickerMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *StickerMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"StickerMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of StickerMessage
|
[
"WithQuickReplies",
"method",
"of",
"StickerMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L234-L237
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *TemplateMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Template Template `json:"template"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeTemplate,
AltText: m.AltText,
Template: m.Template,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *TemplateMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Template Template `json:"template"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeTemplate,
AltText: m.AltText,
Template: m.Template,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"TemplateMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"AltText",
"string",
"`json:\"altText\"`",
"\n",
"Template",
"Template",
"`json:\"template\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeTemplate",
",",
"AltText",
":",
"m",
".",
"AltText",
",",
"Template",
":",
"m",
".",
"Template",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of TemplateMessage
|
[
"MarshalJSON",
"method",
"of",
"TemplateMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L248-L260
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *TemplateMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *TemplateMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"TemplateMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of TemplateMessage
|
[
"WithQuickReplies",
"method",
"of",
"TemplateMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L263-L266
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *ImagemapMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
BaseURL string `json:"baseUrl"`
AltText string `json:"altText"`
BaseSize ImagemapBaseSize `json:"baseSize"`
Actions []ImagemapAction `json:"actions"`
Video *ImagemapVideo `json:"video,omitempty"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeImagemap,
BaseURL: m.BaseURL,
AltText: m.AltText,
BaseSize: m.BaseSize,
Actions: m.Actions,
Video: m.Video,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *ImagemapMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
BaseURL string `json:"baseUrl"`
AltText string `json:"altText"`
BaseSize ImagemapBaseSize `json:"baseSize"`
Actions []ImagemapAction `json:"actions"`
Video *ImagemapVideo `json:"video,omitempty"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeImagemap,
BaseURL: m.BaseURL,
AltText: m.AltText,
BaseSize: m.BaseSize,
Actions: m.Actions,
Video: m.Video,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"ImagemapMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"BaseURL",
"string",
"`json:\"baseUrl\"`",
"\n",
"AltText",
"string",
"`json:\"altText\"`",
"\n",
"BaseSize",
"ImagemapBaseSize",
"`json:\"baseSize\"`",
"\n",
"Actions",
"[",
"]",
"ImagemapAction",
"`json:\"actions\"`",
"\n",
"Video",
"*",
"ImagemapVideo",
"`json:\"video,omitempty\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeImagemap",
",",
"BaseURL",
":",
"m",
".",
"BaseURL",
",",
"AltText",
":",
"m",
".",
"AltText",
",",
"BaseSize",
":",
"m",
".",
"BaseSize",
",",
"Actions",
":",
"m",
".",
"Actions",
",",
"Video",
":",
"m",
".",
"Video",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of ImagemapMessage
|
[
"MarshalJSON",
"method",
"of",
"ImagemapMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L280-L298
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *ImagemapMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *ImagemapMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"ImagemapMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of ImagemapMessage
|
[
"WithQuickReplies",
"method",
"of",
"ImagemapMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L307-L310
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
MarshalJSON
|
func (m *FlexMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Contents interface{} `json:"contents"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeFlex,
AltText: m.AltText,
Contents: m.Contents,
QuickReply: m.quickReplyitems,
})
}
|
go
|
func (m *FlexMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Contents interface{} `json:"contents"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeFlex,
AltText: m.AltText,
Contents: m.Contents,
QuickReply: m.quickReplyitems,
})
}
|
[
"func",
"(",
"m",
"*",
"FlexMessage",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Type",
"MessageType",
"`json:\"type\"`",
"\n",
"AltText",
"string",
"`json:\"altText\"`",
"\n",
"Contents",
"interface",
"{",
"}",
"`json:\"contents\"`",
"\n",
"QuickReply",
"*",
"QuickReplyItems",
"`json:\"quickReply,omitempty\"`",
"\n",
"}",
"{",
"Type",
":",
"MessageTypeFlex",
",",
"AltText",
":",
"m",
".",
"AltText",
",",
"Contents",
":",
"m",
".",
"Contents",
",",
"QuickReply",
":",
"m",
".",
"quickReplyitems",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON method of FlexMessage
|
[
"MarshalJSON",
"method",
"of",
"FlexMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L321-L333
|
train
|
line/line-bot-sdk-go
|
linebot/message.go
|
WithQuickReplies
|
func (m *FlexMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
go
|
func (m *FlexMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
}
|
[
"func",
"(",
"m",
"*",
"FlexMessage",
")",
"WithQuickReplies",
"(",
"items",
"*",
"QuickReplyItems",
")",
"SendingMessage",
"{",
"m",
".",
"quickReplyitems",
"=",
"items",
"\n",
"return",
"m",
"\n",
"}"
] |
// WithQuickReplies method of FlexMessage
|
[
"WithQuickReplies",
"method",
"of",
"FlexMessage"
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/message.go#L336-L339
|
train
|
line/line-bot-sdk-go
|
linebot/get_ids.go
|
NewScanner
|
func (call *GetGroupMemberIDsCall) NewScanner() *IDsScanner {
var ctx context.Context
if call.ctx != nil {
ctx = call.ctx
} else {
ctx = context.Background()
}
c2 := &GetGroupMemberIDsCall{}
*c2 = *call
c2.ctx = ctx
return &IDsScanner{
caller: c2,
ctx: ctx,
}
}
|
go
|
func (call *GetGroupMemberIDsCall) NewScanner() *IDsScanner {
var ctx context.Context
if call.ctx != nil {
ctx = call.ctx
} else {
ctx = context.Background()
}
c2 := &GetGroupMemberIDsCall{}
*c2 = *call
c2.ctx = ctx
return &IDsScanner{
caller: c2,
ctx: ctx,
}
}
|
[
"func",
"(",
"call",
"*",
"GetGroupMemberIDsCall",
")",
"NewScanner",
"(",
")",
"*",
"IDsScanner",
"{",
"var",
"ctx",
"context",
".",
"Context",
"\n",
"if",
"call",
".",
"ctx",
"!=",
"nil",
"{",
"ctx",
"=",
"call",
".",
"ctx",
"\n",
"}",
"else",
"{",
"ctx",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"}",
"\n\n",
"c2",
":=",
"&",
"GetGroupMemberIDsCall",
"{",
"}",
"\n",
"*",
"c2",
"=",
"*",
"call",
"\n",
"c2",
".",
"ctx",
"=",
"ctx",
"\n\n",
"return",
"&",
"IDsScanner",
"{",
"caller",
":",
"c2",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}"
] |
// NewScanner returns Group IDs scanner.
|
[
"NewScanner",
"returns",
"Group",
"IDs",
"scanner",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/get_ids.go#L102-L118
|
train
|
line/line-bot-sdk-go
|
linebot/get_ids.go
|
ID
|
func (s *IDsScanner) ID() string {
if len(s.ids) == 0 {
return ""
}
return s.ids[s.start : s.start+1][0]
}
|
go
|
func (s *IDsScanner) ID() string {
if len(s.ids) == 0 {
return ""
}
return s.ids[s.start : s.start+1][0]
}
|
[
"func",
"(",
"s",
"*",
"IDsScanner",
")",
"ID",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"s",
".",
"ids",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"s",
".",
"ids",
"[",
"s",
".",
"start",
":",
"s",
".",
"start",
"+",
"1",
"]",
"[",
"0",
"]",
"\n",
"}"
] |
// ID returns member id.
|
[
"ID",
"returns",
"member",
"id",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/get_ids.go#L204-L209
|
train
|
line/line-bot-sdk-go
|
linebot/httphandler/httphandler.go
|
New
|
func New(channelSecret, channelToken string) (*WebhookHandler, error) {
if channelSecret == "" {
return nil, errors.New("missing channel secret")
}
if channelToken == "" {
return nil, errors.New("missing channel access token")
}
h := &WebhookHandler{
channelSecret: channelSecret,
channelToken: channelToken,
}
return h, nil
}
|
go
|
func New(channelSecret, channelToken string) (*WebhookHandler, error) {
if channelSecret == "" {
return nil, errors.New("missing channel secret")
}
if channelToken == "" {
return nil, errors.New("missing channel access token")
}
h := &WebhookHandler{
channelSecret: channelSecret,
channelToken: channelToken,
}
return h, nil
}
|
[
"func",
"New",
"(",
"channelSecret",
",",
"channelToken",
"string",
")",
"(",
"*",
"WebhookHandler",
",",
"error",
")",
"{",
"if",
"channelSecret",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"channelToken",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"h",
":=",
"&",
"WebhookHandler",
"{",
"channelSecret",
":",
"channelSecret",
",",
"channelToken",
":",
"channelToken",
",",
"}",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
] |
// New returns a new WebhookHandler instance.
|
[
"New",
"returns",
"a",
"new",
"WebhookHandler",
"instance",
"."
] |
e03995617323053fcafcf0bfe1a66aa96b26ac01
|
https://github.com/line/line-bot-sdk-go/blob/e03995617323053fcafcf0bfe1a66aa96b26ac01/linebot/httphandler/httphandler.go#L40-L52
|
train
|
nicksnyder/go-i18n
|
v2/i18n/localizer.go
|
Localize
|
func (l *Localizer) Localize(lc *LocalizeConfig) (string, error) {
msg, _, err := l.LocalizeWithTag(lc)
return msg, err
}
|
go
|
func (l *Localizer) Localize(lc *LocalizeConfig) (string, error) {
msg, _, err := l.LocalizeWithTag(lc)
return msg, err
}
|
[
"func",
"(",
"l",
"*",
"Localizer",
")",
"Localize",
"(",
"lc",
"*",
"LocalizeConfig",
")",
"(",
"string",
",",
"error",
")",
"{",
"msg",
",",
"_",
",",
"err",
":=",
"l",
".",
"LocalizeWithTag",
"(",
"lc",
")",
"\n",
"return",
"msg",
",",
"err",
"\n",
"}"
] |
// Localize returns a localized message.
|
[
"Localize",
"returns",
"a",
"localized",
"message",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/localizer.go#L104-L107
|
train
|
nicksnyder/go-i18n
|
v2/i18n/localizer.go
|
LocalizeWithTag
|
func (l *Localizer) LocalizeWithTag(lc *LocalizeConfig) (string, language.Tag, error) {
messageID := lc.MessageID
if lc.DefaultMessage != nil {
if messageID != "" && messageID != lc.DefaultMessage.ID {
return "", language.Und, &messageIDMismatchErr{messageID: messageID, defaultMessageID: lc.DefaultMessage.ID}
}
messageID = lc.DefaultMessage.ID
}
var operands *plural.Operands
templateData := lc.TemplateData
if lc.PluralCount != nil {
var err error
operands, err = plural.NewOperands(lc.PluralCount)
if err != nil {
return "", language.Und, &invalidPluralCountErr{messageID: messageID, pluralCount: lc.PluralCount, err: err}
}
if templateData == nil {
templateData = map[string]interface{}{
"PluralCount": lc.PluralCount,
}
}
}
tag, template := l.getTemplate(messageID, lc.DefaultMessage)
if template == nil {
return "", language.Und, &MessageNotFoundErr{messageID: messageID}
}
pluralForm := l.pluralForm(tag, operands)
if pluralForm == plural.Invalid {
return "", language.Und, &pluralizeErr{messageID: messageID, tag: tag}
}
msg, err := template.Execute(pluralForm, templateData, lc.Funcs)
if err != nil {
return "", language.Und, err
}
return msg, tag, nil
}
|
go
|
func (l *Localizer) LocalizeWithTag(lc *LocalizeConfig) (string, language.Tag, error) {
messageID := lc.MessageID
if lc.DefaultMessage != nil {
if messageID != "" && messageID != lc.DefaultMessage.ID {
return "", language.Und, &messageIDMismatchErr{messageID: messageID, defaultMessageID: lc.DefaultMessage.ID}
}
messageID = lc.DefaultMessage.ID
}
var operands *plural.Operands
templateData := lc.TemplateData
if lc.PluralCount != nil {
var err error
operands, err = plural.NewOperands(lc.PluralCount)
if err != nil {
return "", language.Und, &invalidPluralCountErr{messageID: messageID, pluralCount: lc.PluralCount, err: err}
}
if templateData == nil {
templateData = map[string]interface{}{
"PluralCount": lc.PluralCount,
}
}
}
tag, template := l.getTemplate(messageID, lc.DefaultMessage)
if template == nil {
return "", language.Und, &MessageNotFoundErr{messageID: messageID}
}
pluralForm := l.pluralForm(tag, operands)
if pluralForm == plural.Invalid {
return "", language.Und, &pluralizeErr{messageID: messageID, tag: tag}
}
msg, err := template.Execute(pluralForm, templateData, lc.Funcs)
if err != nil {
return "", language.Und, err
}
return msg, tag, nil
}
|
[
"func",
"(",
"l",
"*",
"Localizer",
")",
"LocalizeWithTag",
"(",
"lc",
"*",
"LocalizeConfig",
")",
"(",
"string",
",",
"language",
".",
"Tag",
",",
"error",
")",
"{",
"messageID",
":=",
"lc",
".",
"MessageID",
"\n",
"if",
"lc",
".",
"DefaultMessage",
"!=",
"nil",
"{",
"if",
"messageID",
"!=",
"\"",
"\"",
"&&",
"messageID",
"!=",
"lc",
".",
"DefaultMessage",
".",
"ID",
"{",
"return",
"\"",
"\"",
",",
"language",
".",
"Und",
",",
"&",
"messageIDMismatchErr",
"{",
"messageID",
":",
"messageID",
",",
"defaultMessageID",
":",
"lc",
".",
"DefaultMessage",
".",
"ID",
"}",
"\n",
"}",
"\n",
"messageID",
"=",
"lc",
".",
"DefaultMessage",
".",
"ID",
"\n",
"}",
"\n\n",
"var",
"operands",
"*",
"plural",
".",
"Operands",
"\n",
"templateData",
":=",
"lc",
".",
"TemplateData",
"\n",
"if",
"lc",
".",
"PluralCount",
"!=",
"nil",
"{",
"var",
"err",
"error",
"\n",
"operands",
",",
"err",
"=",
"plural",
".",
"NewOperands",
"(",
"lc",
".",
"PluralCount",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"language",
".",
"Und",
",",
"&",
"invalidPluralCountErr",
"{",
"messageID",
":",
"messageID",
",",
"pluralCount",
":",
"lc",
".",
"PluralCount",
",",
"err",
":",
"err",
"}",
"\n",
"}",
"\n",
"if",
"templateData",
"==",
"nil",
"{",
"templateData",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"lc",
".",
"PluralCount",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"tag",
",",
"template",
":=",
"l",
".",
"getTemplate",
"(",
"messageID",
",",
"lc",
".",
"DefaultMessage",
")",
"\n",
"if",
"template",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"language",
".",
"Und",
",",
"&",
"MessageNotFoundErr",
"{",
"messageID",
":",
"messageID",
"}",
"\n",
"}",
"\n",
"pluralForm",
":=",
"l",
".",
"pluralForm",
"(",
"tag",
",",
"operands",
")",
"\n",
"if",
"pluralForm",
"==",
"plural",
".",
"Invalid",
"{",
"return",
"\"",
"\"",
",",
"language",
".",
"Und",
",",
"&",
"pluralizeErr",
"{",
"messageID",
":",
"messageID",
",",
"tag",
":",
"tag",
"}",
"\n",
"}",
"\n",
"msg",
",",
"err",
":=",
"template",
".",
"Execute",
"(",
"pluralForm",
",",
"templateData",
",",
"lc",
".",
"Funcs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"language",
".",
"Und",
",",
"err",
"\n",
"}",
"\n",
"return",
"msg",
",",
"tag",
",",
"nil",
"\n",
"}"
] |
// LocalizeWithTag returns a localized message and the language tag.
|
[
"LocalizeWithTag",
"returns",
"a",
"localized",
"message",
"and",
"the",
"language",
"tag",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/localizer.go#L110-L146
|
train
|
nicksnyder/go-i18n
|
v2/i18n/localizer.go
|
MustLocalize
|
func (l *Localizer) MustLocalize(lc *LocalizeConfig) string {
localized, err := l.Localize(lc)
if err != nil {
panic(err)
}
return localized
}
|
go
|
func (l *Localizer) MustLocalize(lc *LocalizeConfig) string {
localized, err := l.Localize(lc)
if err != nil {
panic(err)
}
return localized
}
|
[
"func",
"(",
"l",
"*",
"Localizer",
")",
"MustLocalize",
"(",
"lc",
"*",
"LocalizeConfig",
")",
"string",
"{",
"localized",
",",
"err",
":=",
"l",
".",
"Localize",
"(",
"lc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"localized",
"\n",
"}"
] |
// MustLocalize is similar to Localize, except it panics if an error happens.
|
[
"MustLocalize",
"is",
"similar",
"to",
"Localize",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/localizer.go#L203-L209
|
train
|
nicksnyder/go-i18n
|
v2/internal/parse.go
|
ParseMessageFileBytes
|
func ParseMessageFileBytes(buf []byte, path string, unmarshalFuncs map[string]UnmarshalFunc) (*MessageFile, error) {
lang, format := parsePath(path)
tag := language.Make(lang)
messageFile := &MessageFile{
Path: path,
Tag: tag,
Format: format,
}
if len(buf) == 0 {
return messageFile, nil
}
unmarshalFunc := unmarshalFuncs[messageFile.Format]
if unmarshalFunc == nil {
if messageFile.Format == "json" {
unmarshalFunc = json.Unmarshal
} else {
return nil, fmt.Errorf("no unmarshaler registered for %s", messageFile.Format)
}
}
var err error
var raw interface{}
if err = unmarshalFunc(buf, &raw); err != nil {
return nil, err
}
if messageFile.Messages, err = recGetMessages(raw, isMessage(raw), true); err != nil {
return nil, err
}
return messageFile, nil
}
|
go
|
func ParseMessageFileBytes(buf []byte, path string, unmarshalFuncs map[string]UnmarshalFunc) (*MessageFile, error) {
lang, format := parsePath(path)
tag := language.Make(lang)
messageFile := &MessageFile{
Path: path,
Tag: tag,
Format: format,
}
if len(buf) == 0 {
return messageFile, nil
}
unmarshalFunc := unmarshalFuncs[messageFile.Format]
if unmarshalFunc == nil {
if messageFile.Format == "json" {
unmarshalFunc = json.Unmarshal
} else {
return nil, fmt.Errorf("no unmarshaler registered for %s", messageFile.Format)
}
}
var err error
var raw interface{}
if err = unmarshalFunc(buf, &raw); err != nil {
return nil, err
}
if messageFile.Messages, err = recGetMessages(raw, isMessage(raw), true); err != nil {
return nil, err
}
return messageFile, nil
}
|
[
"func",
"ParseMessageFileBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"path",
"string",
",",
"unmarshalFuncs",
"map",
"[",
"string",
"]",
"UnmarshalFunc",
")",
"(",
"*",
"MessageFile",
",",
"error",
")",
"{",
"lang",
",",
"format",
":=",
"parsePath",
"(",
"path",
")",
"\n",
"tag",
":=",
"language",
".",
"Make",
"(",
"lang",
")",
"\n",
"messageFile",
":=",
"&",
"MessageFile",
"{",
"Path",
":",
"path",
",",
"Tag",
":",
"tag",
",",
"Format",
":",
"format",
",",
"}",
"\n",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"messageFile",
",",
"nil",
"\n",
"}",
"\n",
"unmarshalFunc",
":=",
"unmarshalFuncs",
"[",
"messageFile",
".",
"Format",
"]",
"\n",
"if",
"unmarshalFunc",
"==",
"nil",
"{",
"if",
"messageFile",
".",
"Format",
"==",
"\"",
"\"",
"{",
"unmarshalFunc",
"=",
"json",
".",
"Unmarshal",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"messageFile",
".",
"Format",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"var",
"raw",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"unmarshalFunc",
"(",
"buf",
",",
"&",
"raw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"messageFile",
".",
"Messages",
",",
"err",
"=",
"recGetMessages",
"(",
"raw",
",",
"isMessage",
"(",
"raw",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"messageFile",
",",
"nil",
"\n",
"}"
] |
// ParseMessageFileBytes returns the messages parsed from file.
|
[
"ParseMessageFileBytes",
"returns",
"the",
"messages",
"parsed",
"from",
"file",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/parse.go#L24-L54
|
train
|
nicksnyder/go-i18n
|
v2/internal/parse.go
|
recGetMessages
|
func recGetMessages(raw interface{}, isMapMessage, isInitialCall bool) ([]*Message, error) {
var messages []*Message
var err error
switch data := raw.(type) {
case string:
if isInitialCall {
return nil, errInvalidTranslationFile
}
m, err := NewMessage(data)
return []*Message{m}, err
case map[string]interface{}:
if isMapMessage {
m, err := NewMessage(data)
return []*Message{m}, err
}
messages = make([]*Message, 0, len(data))
for id, data := range data {
// recursively scan map items
messages, err = addChildMessages(id, data, messages)
if err != nil {
return nil, err
}
}
case map[interface{}]interface{}:
if isMapMessage {
m, err := NewMessage(data)
return []*Message{m}, err
}
messages = make([]*Message, 0, len(data))
for id, data := range data {
strid, ok := id.(string)
if !ok {
return nil, fmt.Errorf("expected key to be string but got %#v", id)
}
// recursively scan map items
messages, err = addChildMessages(strid, data, messages)
if err != nil {
return nil, err
}
}
case []interface{}:
// Backward compatibility for v1 file format.
messages = make([]*Message, 0, len(data))
for _, data := range data {
// recursively scan slice items
childMessages, err := recGetMessages(data, isMessage(data), false)
if err != nil {
return nil, err
}
messages = append(messages, childMessages...)
}
default:
return nil, fmt.Errorf("unsupported file format %T", raw)
}
return messages, nil
}
|
go
|
func recGetMessages(raw interface{}, isMapMessage, isInitialCall bool) ([]*Message, error) {
var messages []*Message
var err error
switch data := raw.(type) {
case string:
if isInitialCall {
return nil, errInvalidTranslationFile
}
m, err := NewMessage(data)
return []*Message{m}, err
case map[string]interface{}:
if isMapMessage {
m, err := NewMessage(data)
return []*Message{m}, err
}
messages = make([]*Message, 0, len(data))
for id, data := range data {
// recursively scan map items
messages, err = addChildMessages(id, data, messages)
if err != nil {
return nil, err
}
}
case map[interface{}]interface{}:
if isMapMessage {
m, err := NewMessage(data)
return []*Message{m}, err
}
messages = make([]*Message, 0, len(data))
for id, data := range data {
strid, ok := id.(string)
if !ok {
return nil, fmt.Errorf("expected key to be string but got %#v", id)
}
// recursively scan map items
messages, err = addChildMessages(strid, data, messages)
if err != nil {
return nil, err
}
}
case []interface{}:
// Backward compatibility for v1 file format.
messages = make([]*Message, 0, len(data))
for _, data := range data {
// recursively scan slice items
childMessages, err := recGetMessages(data, isMessage(data), false)
if err != nil {
return nil, err
}
messages = append(messages, childMessages...)
}
default:
return nil, fmt.Errorf("unsupported file format %T", raw)
}
return messages, nil
}
|
[
"func",
"recGetMessages",
"(",
"raw",
"interface",
"{",
"}",
",",
"isMapMessage",
",",
"isInitialCall",
"bool",
")",
"(",
"[",
"]",
"*",
"Message",
",",
"error",
")",
"{",
"var",
"messages",
"[",
"]",
"*",
"Message",
"\n",
"var",
"err",
"error",
"\n\n",
"switch",
"data",
":=",
"raw",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"if",
"isInitialCall",
"{",
"return",
"nil",
",",
"errInvalidTranslationFile",
"\n",
"}",
"\n",
"m",
",",
"err",
":=",
"NewMessage",
"(",
"data",
")",
"\n",
"return",
"[",
"]",
"*",
"Message",
"{",
"m",
"}",
",",
"err",
"\n\n",
"case",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"if",
"isMapMessage",
"{",
"m",
",",
"err",
":=",
"NewMessage",
"(",
"data",
")",
"\n",
"return",
"[",
"]",
"*",
"Message",
"{",
"m",
"}",
",",
"err",
"\n",
"}",
"\n",
"messages",
"=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"len",
"(",
"data",
")",
")",
"\n",
"for",
"id",
",",
"data",
":=",
"range",
"data",
"{",
"// recursively scan map items",
"messages",
",",
"err",
"=",
"addChildMessages",
"(",
"id",
",",
"data",
",",
"messages",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
":",
"if",
"isMapMessage",
"{",
"m",
",",
"err",
":=",
"NewMessage",
"(",
"data",
")",
"\n",
"return",
"[",
"]",
"*",
"Message",
"{",
"m",
"}",
",",
"err",
"\n",
"}",
"\n",
"messages",
"=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"len",
"(",
"data",
")",
")",
"\n",
"for",
"id",
",",
"data",
":=",
"range",
"data",
"{",
"strid",
",",
"ok",
":=",
"id",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"// recursively scan map items",
"messages",
",",
"err",
"=",
"addChildMessages",
"(",
"strid",
",",
"data",
",",
"messages",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"// Backward compatibility for v1 file format.",
"messages",
"=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"len",
"(",
"data",
")",
")",
"\n",
"for",
"_",
",",
"data",
":=",
"range",
"data",
"{",
"// recursively scan slice items",
"childMessages",
",",
"err",
":=",
"recGetMessages",
"(",
"data",
",",
"isMessage",
"(",
"data",
")",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"messages",
"=",
"append",
"(",
"messages",
",",
"childMessages",
"...",
")",
"\n",
"}",
"\n\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"return",
"messages",
",",
"nil",
"\n",
"}"
] |
// recGetMessages looks for translation messages inside "raw" parameter,
// scanning nested maps using recursion.
|
[
"recGetMessages",
"looks",
"for",
"translation",
"messages",
"inside",
"raw",
"parameter",
"scanning",
"nested",
"maps",
"using",
"recursion",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/parse.go#L62-L123
|
train
|
nicksnyder/go-i18n
|
v2/goi18n/extract_command.go
|
extractMessages
|
func extractMessages(buf []byte) ([]*i18n.Message, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "", buf, parser.AllErrors)
if err != nil {
return nil, err
}
extractor := newExtractor(file)
ast.Walk(extractor, file)
return extractor.messages, nil
}
|
go
|
func extractMessages(buf []byte) ([]*i18n.Message, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "", buf, parser.AllErrors)
if err != nil {
return nil, err
}
extractor := newExtractor(file)
ast.Walk(extractor, file)
return extractor.messages, nil
}
|
[
"func",
"extractMessages",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"*",
"i18n",
".",
"Message",
",",
"error",
")",
"{",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"file",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"\"",
"\"",
",",
"buf",
",",
"parser",
".",
"AllErrors",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"extractor",
":=",
"newExtractor",
"(",
"file",
")",
"\n",
"ast",
".",
"Walk",
"(",
"extractor",
",",
"file",
")",
"\n",
"return",
"extractor",
".",
"messages",
",",
"nil",
"\n",
"}"
] |
// extractMessages extracts messages from the bytes of a Go source file.
|
[
"extractMessages",
"extracts",
"messages",
"from",
"the",
"bytes",
"of",
"a",
"Go",
"source",
"file",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/goi18n/extract_command.go#L117-L126
|
train
|
nicksnyder/go-i18n
|
i18n/language/pluralspec.go
|
RegisterPluralSpec
|
func RegisterPluralSpec(ids []string, ps *PluralSpec) {
for _, id := range ids {
id = normalizePluralSpecID(id)
pluralSpecs[id] = ps
}
}
|
go
|
func RegisterPluralSpec(ids []string, ps *PluralSpec) {
for _, id := range ids {
id = normalizePluralSpecID(id)
pluralSpecs[id] = ps
}
}
|
[
"func",
"RegisterPluralSpec",
"(",
"ids",
"[",
"]",
"string",
",",
"ps",
"*",
"PluralSpec",
")",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"id",
"=",
"normalizePluralSpecID",
"(",
"id",
")",
"\n",
"pluralSpecs",
"[",
"id",
"]",
"=",
"ps",
"\n",
"}",
"\n",
"}"
] |
// RegisterPluralSpec registers a new plural spec for the language ids.
|
[
"RegisterPluralSpec",
"registers",
"a",
"new",
"plural",
"spec",
"for",
"the",
"language",
"ids",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/pluralspec.go#L22-L27
|
train
|
nicksnyder/go-i18n
|
i18n/language/pluralspec.go
|
Plural
|
func (ps *PluralSpec) Plural(number interface{}) (Plural, error) {
ops, err := newOperands(number)
if err != nil {
return Invalid, err
}
return ps.PluralFunc(ops), nil
}
|
go
|
func (ps *PluralSpec) Plural(number interface{}) (Plural, error) {
ops, err := newOperands(number)
if err != nil {
return Invalid, err
}
return ps.PluralFunc(ops), nil
}
|
[
"func",
"(",
"ps",
"*",
"PluralSpec",
")",
"Plural",
"(",
"number",
"interface",
"{",
"}",
")",
"(",
"Plural",
",",
"error",
")",
"{",
"ops",
",",
"err",
":=",
"newOperands",
"(",
"number",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Invalid",
",",
"err",
"\n",
"}",
"\n",
"return",
"ps",
".",
"PluralFunc",
"(",
"ops",
")",
",",
"nil",
"\n",
"}"
] |
// Plural returns the plural category for number as defined by
// the language's CLDR plural rules.
|
[
"Plural",
"returns",
"the",
"plural",
"category",
"for",
"number",
"as",
"defined",
"by",
"the",
"language",
"s",
"CLDR",
"plural",
"rules",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/pluralspec.go#L31-L37
|
train
|
nicksnyder/go-i18n
|
i18n/language/pluralspec.go
|
GetPluralSpec
|
func GetPluralSpec(tag string) *PluralSpec {
tag = NormalizeTag(tag)
subtag := tag
for {
if spec := pluralSpecs[subtag]; spec != nil {
return spec
}
end := strings.LastIndex(subtag, "-")
if end == -1 {
return nil
}
subtag = subtag[:end]
}
}
|
go
|
func GetPluralSpec(tag string) *PluralSpec {
tag = NormalizeTag(tag)
subtag := tag
for {
if spec := pluralSpecs[subtag]; spec != nil {
return spec
}
end := strings.LastIndex(subtag, "-")
if end == -1 {
return nil
}
subtag = subtag[:end]
}
}
|
[
"func",
"GetPluralSpec",
"(",
"tag",
"string",
")",
"*",
"PluralSpec",
"{",
"tag",
"=",
"NormalizeTag",
"(",
"tag",
")",
"\n",
"subtag",
":=",
"tag",
"\n",
"for",
"{",
"if",
"spec",
":=",
"pluralSpecs",
"[",
"subtag",
"]",
";",
"spec",
"!=",
"nil",
"{",
"return",
"spec",
"\n",
"}",
"\n",
"end",
":=",
"strings",
".",
"LastIndex",
"(",
"subtag",
",",
"\"",
"\"",
")",
"\n",
"if",
"end",
"==",
"-",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"subtag",
"=",
"subtag",
"[",
":",
"end",
"]",
"\n",
"}",
"\n",
"}"
] |
// GetPluralSpec returns the PluralSpec that matches the longest prefix of tag.
// It returns nil if no PluralSpec matches tag.
|
[
"GetPluralSpec",
"returns",
"the",
"PluralSpec",
"that",
"matches",
"the",
"longest",
"prefix",
"of",
"tag",
".",
"It",
"returns",
"nil",
"if",
"no",
"PluralSpec",
"matches",
"tag",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/pluralspec.go#L41-L54
|
train
|
nicksnyder/go-i18n
|
i18n/language/language.go
|
Parse
|
func Parse(src string) []*Language {
var langs []*Language
start := 0
for end, chr := range src {
switch chr {
case ',', ';', '.':
tag := strings.TrimSpace(src[start:end])
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
start = end + 1
}
}
if start > 0 {
tag := strings.TrimSpace(src[start:])
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
return dedupe(langs)
}
if spec := GetPluralSpec(src); spec != nil {
langs = append(langs, &Language{NormalizeTag(src), spec})
}
return langs
}
|
go
|
func Parse(src string) []*Language {
var langs []*Language
start := 0
for end, chr := range src {
switch chr {
case ',', ';', '.':
tag := strings.TrimSpace(src[start:end])
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
start = end + 1
}
}
if start > 0 {
tag := strings.TrimSpace(src[start:])
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
return dedupe(langs)
}
if spec := GetPluralSpec(src); spec != nil {
langs = append(langs, &Language{NormalizeTag(src), spec})
}
return langs
}
|
[
"func",
"Parse",
"(",
"src",
"string",
")",
"[",
"]",
"*",
"Language",
"{",
"var",
"langs",
"[",
"]",
"*",
"Language",
"\n",
"start",
":=",
"0",
"\n",
"for",
"end",
",",
"chr",
":=",
"range",
"src",
"{",
"switch",
"chr",
"{",
"case",
"','",
",",
"';'",
",",
"'.'",
":",
"tag",
":=",
"strings",
".",
"TrimSpace",
"(",
"src",
"[",
"start",
":",
"end",
"]",
")",
"\n",
"if",
"spec",
":=",
"GetPluralSpec",
"(",
"tag",
")",
";",
"spec",
"!=",
"nil",
"{",
"langs",
"=",
"append",
"(",
"langs",
",",
"&",
"Language",
"{",
"NormalizeTag",
"(",
"tag",
")",
",",
"spec",
"}",
")",
"\n",
"}",
"\n",
"start",
"=",
"end",
"+",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"start",
">",
"0",
"{",
"tag",
":=",
"strings",
".",
"TrimSpace",
"(",
"src",
"[",
"start",
":",
"]",
")",
"\n",
"if",
"spec",
":=",
"GetPluralSpec",
"(",
"tag",
")",
";",
"spec",
"!=",
"nil",
"{",
"langs",
"=",
"append",
"(",
"langs",
",",
"&",
"Language",
"{",
"NormalizeTag",
"(",
"tag",
")",
",",
"spec",
"}",
")",
"\n",
"}",
"\n",
"return",
"dedupe",
"(",
"langs",
")",
"\n",
"}",
"\n",
"if",
"spec",
":=",
"GetPluralSpec",
"(",
"src",
")",
";",
"spec",
"!=",
"nil",
"{",
"langs",
"=",
"append",
"(",
"langs",
",",
"&",
"Language",
"{",
"NormalizeTag",
"(",
"src",
")",
",",
"spec",
"}",
")",
"\n",
"}",
"\n",
"return",
"langs",
"\n",
"}"
] |
// Parse returns a slice of supported languages found in src or nil if none are found.
// It can parse language tags and Accept-Language headers.
|
[
"Parse",
"returns",
"a",
"slice",
"of",
"supported",
"languages",
"found",
"in",
"src",
"or",
"nil",
"if",
"none",
"are",
"found",
".",
"It",
"can",
"parse",
"language",
"tags",
"and",
"Accept",
"-",
"Language",
"headers",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/language.go#L41-L65
|
train
|
nicksnyder/go-i18n
|
i18n/language/language.go
|
MustParse
|
func MustParse(src string) []*Language {
langs := Parse(src)
if len(langs) == 0 {
panic(fmt.Errorf("unable to parse language from %q", src))
}
return langs
}
|
go
|
func MustParse(src string) []*Language {
langs := Parse(src)
if len(langs) == 0 {
panic(fmt.Errorf("unable to parse language from %q", src))
}
return langs
}
|
[
"func",
"MustParse",
"(",
"src",
"string",
")",
"[",
"]",
"*",
"Language",
"{",
"langs",
":=",
"Parse",
"(",
"src",
")",
"\n",
"if",
"len",
"(",
"langs",
")",
"==",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"src",
")",
")",
"\n",
"}",
"\n",
"return",
"langs",
"\n",
"}"
] |
// MustParse is similar to Parse except it panics instead of retuning a nil Language.
|
[
"MustParse",
"is",
"similar",
"to",
"Parse",
"except",
"it",
"panics",
"instead",
"of",
"retuning",
"a",
"nil",
"Language",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/language.go#L80-L86
|
train
|
nicksnyder/go-i18n
|
i18n/language/language.go
|
Add
|
func Add(l *Language) {
tag := NormalizeTag(l.Tag)
pluralSpecs[tag] = l.PluralSpec
}
|
go
|
func Add(l *Language) {
tag := NormalizeTag(l.Tag)
pluralSpecs[tag] = l.PluralSpec
}
|
[
"func",
"Add",
"(",
"l",
"*",
"Language",
")",
"{",
"tag",
":=",
"NormalizeTag",
"(",
"l",
".",
"Tag",
")",
"\n",
"pluralSpecs",
"[",
"tag",
"]",
"=",
"l",
".",
"PluralSpec",
"\n",
"}"
] |
// Add adds support for a new language.
|
[
"Add",
"adds",
"support",
"for",
"a",
"new",
"language",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/language.go#L89-L92
|
train
|
nicksnyder/go-i18n
|
i18n/language/language.go
|
NormalizeTag
|
func NormalizeTag(tag string) string {
tag = strings.ToLower(tag)
return strings.Replace(tag, "_", "-", -1)
}
|
go
|
func NormalizeTag(tag string) string {
tag = strings.ToLower(tag)
return strings.Replace(tag, "_", "-", -1)
}
|
[
"func",
"NormalizeTag",
"(",
"tag",
"string",
")",
"string",
"{",
"tag",
"=",
"strings",
".",
"ToLower",
"(",
"tag",
")",
"\n",
"return",
"strings",
".",
"Replace",
"(",
"tag",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}"
] |
// NormalizeTag returns a language tag with all lower-case characters
// and dashes "-" instead of underscores "_"
|
[
"NormalizeTag",
"returns",
"a",
"language",
"tag",
"with",
"all",
"lower",
"-",
"case",
"characters",
"and",
"dashes",
"-",
"instead",
"of",
"underscores",
"_"
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/language.go#L96-L99
|
train
|
nicksnyder/go-i18n
|
i18n/i18n.go
|
TfuncAndLanguage
|
func TfuncAndLanguage(languageSource string, languageSources ...string) (TranslateFunc, *language.Language, error) {
tfunc, lang, err := defaultBundle.TfuncAndLanguage(languageSource, languageSources...)
return TranslateFunc(tfunc), lang, err
}
|
go
|
func TfuncAndLanguage(languageSource string, languageSources ...string) (TranslateFunc, *language.Language, error) {
tfunc, lang, err := defaultBundle.TfuncAndLanguage(languageSource, languageSources...)
return TranslateFunc(tfunc), lang, err
}
|
[
"func",
"TfuncAndLanguage",
"(",
"languageSource",
"string",
",",
"languageSources",
"...",
"string",
")",
"(",
"TranslateFunc",
",",
"*",
"language",
".",
"Language",
",",
"error",
")",
"{",
"tfunc",
",",
"lang",
",",
"err",
":=",
"defaultBundle",
".",
"TfuncAndLanguage",
"(",
"languageSource",
",",
"languageSources",
"...",
")",
"\n",
"return",
"TranslateFunc",
"(",
"tfunc",
")",
",",
"lang",
",",
"err",
"\n",
"}"
] |
// TfuncAndLanguage is similar to Tfunc except it also returns the language which TranslateFunc is bound to.
|
[
"TfuncAndLanguage",
"is",
"similar",
"to",
"Tfunc",
"except",
"it",
"also",
"returns",
"the",
"language",
"which",
"TranslateFunc",
"is",
"bound",
"to",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/i18n.go#L155-L158
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
RegisterUnmarshalFunc
|
func (b *Bundle) RegisterUnmarshalFunc(format string, unmarshalFunc UnmarshalFunc) {
if b.unmarshalFuncs == nil {
b.unmarshalFuncs = make(map[string]UnmarshalFunc)
}
b.unmarshalFuncs[format] = unmarshalFunc
}
|
go
|
func (b *Bundle) RegisterUnmarshalFunc(format string, unmarshalFunc UnmarshalFunc) {
if b.unmarshalFuncs == nil {
b.unmarshalFuncs = make(map[string]UnmarshalFunc)
}
b.unmarshalFuncs[format] = unmarshalFunc
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"RegisterUnmarshalFunc",
"(",
"format",
"string",
",",
"unmarshalFunc",
"UnmarshalFunc",
")",
"{",
"if",
"b",
".",
"unmarshalFuncs",
"==",
"nil",
"{",
"b",
".",
"unmarshalFuncs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"UnmarshalFunc",
")",
"\n",
"}",
"\n",
"b",
".",
"unmarshalFuncs",
"[",
"format",
"]",
"=",
"unmarshalFunc",
"\n",
"}"
] |
// RegisterUnmarshalFunc registers an UnmarshalFunc for format.
|
[
"RegisterUnmarshalFunc",
"registers",
"an",
"UnmarshalFunc",
"for",
"format",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L40-L45
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
LoadMessageFile
|
func (b *Bundle) LoadMessageFile(path string) (*MessageFile, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return b.ParseMessageFileBytes(buf, path)
}
|
go
|
func (b *Bundle) LoadMessageFile(path string) (*MessageFile, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return b.ParseMessageFileBytes(buf, path)
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"LoadMessageFile",
"(",
"path",
"string",
")",
"(",
"*",
"MessageFile",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
".",
"ParseMessageFileBytes",
"(",
"buf",
",",
"path",
")",
"\n",
"}"
] |
// LoadMessageFile loads the bytes from path
// and then calls ParseMessageFileBytes.
|
[
"LoadMessageFile",
"loads",
"the",
"bytes",
"from",
"path",
"and",
"then",
"calls",
"ParseMessageFileBytes",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L49-L55
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
MustLoadMessageFile
|
func (b *Bundle) MustLoadMessageFile(path string) {
if _, err := b.LoadMessageFile(path); err != nil {
panic(err)
}
}
|
go
|
func (b *Bundle) MustLoadMessageFile(path string) {
if _, err := b.LoadMessageFile(path); err != nil {
panic(err)
}
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"MustLoadMessageFile",
"(",
"path",
"string",
")",
"{",
"if",
"_",
",",
"err",
":=",
"b",
".",
"LoadMessageFile",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// MustLoadMessageFile is similar to LoadTranslationFile
// except it panics if an error happens.
|
[
"MustLoadMessageFile",
"is",
"similar",
"to",
"LoadTranslationFile",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L59-L63
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
ParseMessageFileBytes
|
func (b *Bundle) ParseMessageFileBytes(buf []byte, path string) (*MessageFile, error) {
messageFile, err := internal.ParseMessageFileBytes(buf, path, b.unmarshalFuncs)
if err != nil {
return nil, err
}
if err := b.AddMessages(messageFile.Tag, messageFile.Messages...); err != nil {
return nil, err
}
return messageFile, nil
}
|
go
|
func (b *Bundle) ParseMessageFileBytes(buf []byte, path string) (*MessageFile, error) {
messageFile, err := internal.ParseMessageFileBytes(buf, path, b.unmarshalFuncs)
if err != nil {
return nil, err
}
if err := b.AddMessages(messageFile.Tag, messageFile.Messages...); err != nil {
return nil, err
}
return messageFile, nil
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"ParseMessageFileBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"path",
"string",
")",
"(",
"*",
"MessageFile",
",",
"error",
")",
"{",
"messageFile",
",",
"err",
":=",
"internal",
".",
"ParseMessageFileBytes",
"(",
"buf",
",",
"path",
",",
"b",
".",
"unmarshalFuncs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"b",
".",
"AddMessages",
"(",
"messageFile",
".",
"Tag",
",",
"messageFile",
".",
"Messages",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"messageFile",
",",
"nil",
"\n",
"}"
] |
// ParseMessageFileBytes parses the bytes in buf to add translations to the bundle.
//
// The format of the file is everything after the last ".".
//
// The language tag of the file is everything after the second to last "." or after the last path separator, but before the format.
|
[
"ParseMessageFileBytes",
"parses",
"the",
"bytes",
"in",
"buf",
"to",
"add",
"translations",
"to",
"the",
"bundle",
".",
"The",
"format",
"of",
"the",
"file",
"is",
"everything",
"after",
"the",
"last",
".",
".",
"The",
"language",
"tag",
"of",
"the",
"file",
"is",
"everything",
"after",
"the",
"second",
"to",
"last",
".",
"or",
"after",
"the",
"last",
"path",
"separator",
"but",
"before",
"the",
"format",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L73-L82
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
MustParseMessageFileBytes
|
func (b *Bundle) MustParseMessageFileBytes(buf []byte, path string) {
if _, err := b.ParseMessageFileBytes(buf, path); err != nil {
panic(err)
}
}
|
go
|
func (b *Bundle) MustParseMessageFileBytes(buf []byte, path string) {
if _, err := b.ParseMessageFileBytes(buf, path); err != nil {
panic(err)
}
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"MustParseMessageFileBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"path",
"string",
")",
"{",
"if",
"_",
",",
"err",
":=",
"b",
".",
"ParseMessageFileBytes",
"(",
"buf",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// MustParseMessageFileBytes is similar to ParseMessageFileBytes
// except it panics if an error happens.
|
[
"MustParseMessageFileBytes",
"is",
"similar",
"to",
"ParseMessageFileBytes",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L86-L90
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
AddMessages
|
func (b *Bundle) AddMessages(tag language.Tag, messages ...*Message) error {
pluralRule := b.pluralRules.Rule(tag)
if pluralRule == nil {
return fmt.Errorf("no plural rule registered for %s", tag)
}
if b.messageTemplates == nil {
b.messageTemplates = map[language.Tag]map[string]*internal.MessageTemplate{}
}
if b.messageTemplates[tag] == nil {
b.messageTemplates[tag] = map[string]*internal.MessageTemplate{}
b.addTag(tag)
}
for _, m := range messages {
b.messageTemplates[tag][m.ID] = internal.NewMessageTemplate(m)
}
return nil
}
|
go
|
func (b *Bundle) AddMessages(tag language.Tag, messages ...*Message) error {
pluralRule := b.pluralRules.Rule(tag)
if pluralRule == nil {
return fmt.Errorf("no plural rule registered for %s", tag)
}
if b.messageTemplates == nil {
b.messageTemplates = map[language.Tag]map[string]*internal.MessageTemplate{}
}
if b.messageTemplates[tag] == nil {
b.messageTemplates[tag] = map[string]*internal.MessageTemplate{}
b.addTag(tag)
}
for _, m := range messages {
b.messageTemplates[tag][m.ID] = internal.NewMessageTemplate(m)
}
return nil
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"AddMessages",
"(",
"tag",
"language",
".",
"Tag",
",",
"messages",
"...",
"*",
"Message",
")",
"error",
"{",
"pluralRule",
":=",
"b",
".",
"pluralRules",
".",
"Rule",
"(",
"tag",
")",
"\n",
"if",
"pluralRule",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"if",
"b",
".",
"messageTemplates",
"==",
"nil",
"{",
"b",
".",
"messageTemplates",
"=",
"map",
"[",
"language",
".",
"Tag",
"]",
"map",
"[",
"string",
"]",
"*",
"internal",
".",
"MessageTemplate",
"{",
"}",
"\n",
"}",
"\n",
"if",
"b",
".",
"messageTemplates",
"[",
"tag",
"]",
"==",
"nil",
"{",
"b",
".",
"messageTemplates",
"[",
"tag",
"]",
"=",
"map",
"[",
"string",
"]",
"*",
"internal",
".",
"MessageTemplate",
"{",
"}",
"\n",
"b",
".",
"addTag",
"(",
"tag",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"messages",
"{",
"b",
".",
"messageTemplates",
"[",
"tag",
"]",
"[",
"m",
".",
"ID",
"]",
"=",
"internal",
".",
"NewMessageTemplate",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddMessages adds messages for a language.
// It is useful if your messages are in a format not supported by ParseMessageFileBytes.
|
[
"AddMessages",
"adds",
"messages",
"for",
"a",
"language",
".",
"It",
"is",
"useful",
"if",
"your",
"messages",
"are",
"in",
"a",
"format",
"not",
"supported",
"by",
"ParseMessageFileBytes",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L94-L110
|
train
|
nicksnyder/go-i18n
|
v2/i18n/bundle.go
|
MustAddMessages
|
func (b *Bundle) MustAddMessages(tag language.Tag, messages ...*Message) {
if err := b.AddMessages(tag, messages...); err != nil {
panic(err)
}
}
|
go
|
func (b *Bundle) MustAddMessages(tag language.Tag, messages ...*Message) {
if err := b.AddMessages(tag, messages...); err != nil {
panic(err)
}
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"MustAddMessages",
"(",
"tag",
"language",
".",
"Tag",
",",
"messages",
"...",
"*",
"Message",
")",
"{",
"if",
"err",
":=",
"b",
".",
"AddMessages",
"(",
"tag",
",",
"messages",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// MustAddMessages is similar to AddMessages except it panics if an error happens.
|
[
"MustAddMessages",
"is",
"similar",
"to",
"AddMessages",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/i18n/bundle.go#L113-L117
|
train
|
nicksnyder/go-i18n
|
i18n/language/operands.go
|
NequalsAny
|
func (o *Operands) NequalsAny(any ...int64) bool {
for _, i := range any {
if o.I == i && o.T == 0 {
return true
}
}
return false
}
|
go
|
func (o *Operands) NequalsAny(any ...int64) bool {
for _, i := range any {
if o.I == i && o.T == 0 {
return true
}
}
return false
}
|
[
"func",
"(",
"o",
"*",
"Operands",
")",
"NequalsAny",
"(",
"any",
"...",
"int64",
")",
"bool",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"any",
"{",
"if",
"o",
".",
"I",
"==",
"i",
"&&",
"o",
".",
"T",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// NequalsAny returns true if o represents an integer equal to any of the arguments.
|
[
"NequalsAny",
"returns",
"true",
"if",
"o",
"represents",
"an",
"integer",
"equal",
"to",
"any",
"of",
"the",
"arguments",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/operands.go#L20-L27
|
train
|
nicksnyder/go-i18n
|
i18n/language/operands.go
|
NmodEqualsAny
|
func (o *Operands) NmodEqualsAny(mod int64, any ...int64) bool {
modI := o.I % mod
for _, i := range any {
if modI == i && o.T == 0 {
return true
}
}
return false
}
|
go
|
func (o *Operands) NmodEqualsAny(mod int64, any ...int64) bool {
modI := o.I % mod
for _, i := range any {
if modI == i && o.T == 0 {
return true
}
}
return false
}
|
[
"func",
"(",
"o",
"*",
"Operands",
")",
"NmodEqualsAny",
"(",
"mod",
"int64",
",",
"any",
"...",
"int64",
")",
"bool",
"{",
"modI",
":=",
"o",
".",
"I",
"%",
"mod",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"any",
"{",
"if",
"modI",
"==",
"i",
"&&",
"o",
".",
"T",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// NmodEqualsAny returns true if o represents an integer equal to any of the arguments modulo mod.
|
[
"NmodEqualsAny",
"returns",
"true",
"if",
"o",
"represents",
"an",
"integer",
"equal",
"to",
"any",
"of",
"the",
"arguments",
"modulo",
"mod",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/operands.go#L30-L38
|
train
|
nicksnyder/go-i18n
|
v2/internal/message.go
|
NewMessage
|
func NewMessage(data interface{}) (*Message, error) {
m := &Message{}
if err := m.unmarshalInterface(data); err != nil {
return nil, err
}
return m, nil
}
|
go
|
func NewMessage(data interface{}) (*Message, error) {
m := &Message{}
if err := m.unmarshalInterface(data); err != nil {
return nil, err
}
return m, nil
}
|
[
"func",
"NewMessage",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"m",
":=",
"&",
"Message",
"{",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"unmarshalInterface",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// NewMessage parses data and returns a new message.
|
[
"NewMessage",
"parses",
"data",
"and",
"returns",
"a",
"new",
"message",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/message.go#L47-L53
|
train
|
nicksnyder/go-i18n
|
v2/internal/message.go
|
MustNewMessage
|
func MustNewMessage(data interface{}) *Message {
m, err := NewMessage(data)
if err != nil {
panic(err)
}
return m
}
|
go
|
func MustNewMessage(data interface{}) *Message {
m, err := NewMessage(data)
if err != nil {
panic(err)
}
return m
}
|
[
"func",
"MustNewMessage",
"(",
"data",
"interface",
"{",
"}",
")",
"*",
"Message",
"{",
"m",
",",
"err",
":=",
"NewMessage",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] |
// MustNewMessage is similar to NewMessage except it panics if an error happens.
|
[
"MustNewMessage",
"is",
"similar",
"to",
"NewMessage",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/message.go#L56-L62
|
train
|
nicksnyder/go-i18n
|
v2/internal/message.go
|
unmarshalInterface
|
func (m *Message) unmarshalInterface(v interface{}) error {
strdata, err := stringMap(v)
if err != nil {
return err
}
for k, v := range strdata {
switch strings.ToLower(k) {
case "id":
m.ID = v
case "description":
m.Description = v
case "hash":
m.Hash = v
case "leftdelim":
m.LeftDelim = v
case "rightdelim":
m.RightDelim = v
case "zero":
m.Zero = v
case "one":
m.One = v
case "two":
m.Two = v
case "few":
m.Few = v
case "many":
m.Many = v
case "other":
m.Other = v
}
}
return nil
}
|
go
|
func (m *Message) unmarshalInterface(v interface{}) error {
strdata, err := stringMap(v)
if err != nil {
return err
}
for k, v := range strdata {
switch strings.ToLower(k) {
case "id":
m.ID = v
case "description":
m.Description = v
case "hash":
m.Hash = v
case "leftdelim":
m.LeftDelim = v
case "rightdelim":
m.RightDelim = v
case "zero":
m.Zero = v
case "one":
m.One = v
case "two":
m.Two = v
case "few":
m.Few = v
case "many":
m.Many = v
case "other":
m.Other = v
}
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Message",
")",
"unmarshalInterface",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"strdata",
",",
"err",
":=",
"stringMap",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"strdata",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"k",
")",
"{",
"case",
"\"",
"\"",
":",
"m",
".",
"ID",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Description",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Hash",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"LeftDelim",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"RightDelim",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Zero",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"One",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Two",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Few",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Many",
"=",
"v",
"\n",
"case",
"\"",
"\"",
":",
"m",
".",
"Other",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// unmarshalInterface unmarshals a message from data.
|
[
"unmarshalInterface",
"unmarshals",
"a",
"message",
"from",
"data",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/message.go#L65-L97
|
train
|
nicksnyder/go-i18n
|
v2/internal/message_template.go
|
NewMessageTemplate
|
func NewMessageTemplate(m *Message) *MessageTemplate {
pluralTemplates := map[plural.Form]*Template{}
setPluralTemplate(pluralTemplates, plural.Zero, m.Zero)
setPluralTemplate(pluralTemplates, plural.One, m.One)
setPluralTemplate(pluralTemplates, plural.Two, m.Two)
setPluralTemplate(pluralTemplates, plural.Few, m.Few)
setPluralTemplate(pluralTemplates, plural.Many, m.Many)
setPluralTemplate(pluralTemplates, plural.Other, m.Other)
if len(pluralTemplates) == 0 {
return nil
}
return &MessageTemplate{
Message: m,
PluralTemplates: pluralTemplates,
}
}
|
go
|
func NewMessageTemplate(m *Message) *MessageTemplate {
pluralTemplates := map[plural.Form]*Template{}
setPluralTemplate(pluralTemplates, plural.Zero, m.Zero)
setPluralTemplate(pluralTemplates, plural.One, m.One)
setPluralTemplate(pluralTemplates, plural.Two, m.Two)
setPluralTemplate(pluralTemplates, plural.Few, m.Few)
setPluralTemplate(pluralTemplates, plural.Many, m.Many)
setPluralTemplate(pluralTemplates, plural.Other, m.Other)
if len(pluralTemplates) == 0 {
return nil
}
return &MessageTemplate{
Message: m,
PluralTemplates: pluralTemplates,
}
}
|
[
"func",
"NewMessageTemplate",
"(",
"m",
"*",
"Message",
")",
"*",
"MessageTemplate",
"{",
"pluralTemplates",
":=",
"map",
"[",
"plural",
".",
"Form",
"]",
"*",
"Template",
"{",
"}",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"Zero",
",",
"m",
".",
"Zero",
")",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"One",
",",
"m",
".",
"One",
")",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"Two",
",",
"m",
".",
"Two",
")",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"Few",
",",
"m",
".",
"Few",
")",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"Many",
",",
"m",
".",
"Many",
")",
"\n",
"setPluralTemplate",
"(",
"pluralTemplates",
",",
"plural",
".",
"Other",
",",
"m",
".",
"Other",
")",
"\n",
"if",
"len",
"(",
"pluralTemplates",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"MessageTemplate",
"{",
"Message",
":",
"m",
",",
"PluralTemplates",
":",
"pluralTemplates",
",",
"}",
"\n",
"}"
] |
// NewMessageTemplate returns a new message template.
|
[
"NewMessageTemplate",
"returns",
"a",
"new",
"message",
"template",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/message_template.go#L19-L34
|
train
|
nicksnyder/go-i18n
|
v2/internal/message_template.go
|
Execute
|
func (mt *MessageTemplate) Execute(pluralForm plural.Form, data interface{}, funcs template.FuncMap) (string, error) {
t := mt.PluralTemplates[pluralForm]
if t == nil {
return "", pluralFormNotFoundError{
pluralForm: pluralForm,
messageID: mt.Message.ID,
}
}
if err := t.parse(mt.LeftDelim, mt.RightDelim, funcs); err != nil {
return "", err
}
if t.Template == nil {
return t.Src, nil
}
var buf bytes.Buffer
if err := t.Template.Execute(&buf, data); err != nil {
return "", err
}
return buf.String(), nil
}
|
go
|
func (mt *MessageTemplate) Execute(pluralForm plural.Form, data interface{}, funcs template.FuncMap) (string, error) {
t := mt.PluralTemplates[pluralForm]
if t == nil {
return "", pluralFormNotFoundError{
pluralForm: pluralForm,
messageID: mt.Message.ID,
}
}
if err := t.parse(mt.LeftDelim, mt.RightDelim, funcs); err != nil {
return "", err
}
if t.Template == nil {
return t.Src, nil
}
var buf bytes.Buffer
if err := t.Template.Execute(&buf, data); err != nil {
return "", err
}
return buf.String(), nil
}
|
[
"func",
"(",
"mt",
"*",
"MessageTemplate",
")",
"Execute",
"(",
"pluralForm",
"plural",
".",
"Form",
",",
"data",
"interface",
"{",
"}",
",",
"funcs",
"template",
".",
"FuncMap",
")",
"(",
"string",
",",
"error",
")",
"{",
"t",
":=",
"mt",
".",
"PluralTemplates",
"[",
"pluralForm",
"]",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"pluralFormNotFoundError",
"{",
"pluralForm",
":",
"pluralForm",
",",
"messageID",
":",
"mt",
".",
"Message",
".",
"ID",
",",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"parse",
"(",
"mt",
".",
"LeftDelim",
",",
"mt",
".",
"RightDelim",
",",
"funcs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"t",
".",
"Template",
"==",
"nil",
"{",
"return",
"t",
".",
"Src",
",",
"nil",
"\n",
"}",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"t",
".",
"Template",
".",
"Execute",
"(",
"&",
"buf",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Execute executes the template for the plural form and template data.
|
[
"Execute",
"executes",
"the",
"template",
"for",
"the",
"plural",
"form",
"and",
"template",
"data",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/message_template.go#L52-L71
|
train
|
nicksnyder/go-i18n
|
v2/internal/plural/operands.go
|
NewOperands
|
func NewOperands(number interface{}) (*Operands, error) {
switch number := number.(type) {
case int:
return newOperandsInt64(int64(number)), nil
case int8:
return newOperandsInt64(int64(number)), nil
case int16:
return newOperandsInt64(int64(number)), nil
case int32:
return newOperandsInt64(int64(number)), nil
case int64:
return newOperandsInt64(number), nil
case string:
return newOperandsString(number)
case float32, float64:
return nil, fmt.Errorf("floats should be formatted into a string")
default:
return nil, fmt.Errorf("invalid type %T; expected integer or string", number)
}
}
|
go
|
func NewOperands(number interface{}) (*Operands, error) {
switch number := number.(type) {
case int:
return newOperandsInt64(int64(number)), nil
case int8:
return newOperandsInt64(int64(number)), nil
case int16:
return newOperandsInt64(int64(number)), nil
case int32:
return newOperandsInt64(int64(number)), nil
case int64:
return newOperandsInt64(number), nil
case string:
return newOperandsString(number)
case float32, float64:
return nil, fmt.Errorf("floats should be formatted into a string")
default:
return nil, fmt.Errorf("invalid type %T; expected integer or string", number)
}
}
|
[
"func",
"NewOperands",
"(",
"number",
"interface",
"{",
"}",
")",
"(",
"*",
"Operands",
",",
"error",
")",
"{",
"switch",
"number",
":=",
"number",
".",
"(",
"type",
")",
"{",
"case",
"int",
":",
"return",
"newOperandsInt64",
"(",
"int64",
"(",
"number",
")",
")",
",",
"nil",
"\n",
"case",
"int8",
":",
"return",
"newOperandsInt64",
"(",
"int64",
"(",
"number",
")",
")",
",",
"nil",
"\n",
"case",
"int16",
":",
"return",
"newOperandsInt64",
"(",
"int64",
"(",
"number",
")",
")",
",",
"nil",
"\n",
"case",
"int32",
":",
"return",
"newOperandsInt64",
"(",
"int64",
"(",
"number",
")",
")",
",",
"nil",
"\n",
"case",
"int64",
":",
"return",
"newOperandsInt64",
"(",
"number",
")",
",",
"nil",
"\n",
"case",
"string",
":",
"return",
"newOperandsString",
"(",
"number",
")",
"\n",
"case",
"float32",
",",
"float64",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"number",
")",
"\n",
"}",
"\n",
"}"
] |
// NewOperands returns the operands for number.
|
[
"NewOperands",
"returns",
"the",
"operands",
"for",
"number",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/internal/plural/operands.go#L52-L71
|
train
|
nicksnyder/go-i18n
|
i18n/language/codegen/xml.go
|
Name
|
func (pg *PluralGroup) Name() string {
n := strings.Title(pg.Locales)
return strings.Replace(n, " ", "", -1)
}
|
go
|
func (pg *PluralGroup) Name() string {
n := strings.Title(pg.Locales)
return strings.Replace(n, " ", "", -1)
}
|
[
"func",
"(",
"pg",
"*",
"PluralGroup",
")",
"Name",
"(",
")",
"string",
"{",
"n",
":=",
"strings",
".",
"Title",
"(",
"pg",
".",
"Locales",
")",
"\n",
"return",
"strings",
".",
"Replace",
"(",
"n",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}"
] |
// Name returns a unique name for this plural group.
|
[
"Name",
"returns",
"a",
"unique",
"name",
"for",
"this",
"plural",
"group",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/codegen/xml.go#L23-L26
|
train
|
nicksnyder/go-i18n
|
i18n/language/codegen/xml.go
|
Condition
|
func (pr *PluralRule) Condition() string {
i := strings.Index(pr.Rule, "@")
return pr.Rule[:i]
}
|
go
|
func (pr *PluralRule) Condition() string {
i := strings.Index(pr.Rule, "@")
return pr.Rule[:i]
}
|
[
"func",
"(",
"pr",
"*",
"PluralRule",
")",
"Condition",
"(",
")",
"string",
"{",
"i",
":=",
"strings",
".",
"Index",
"(",
"pr",
".",
"Rule",
",",
"\"",
"\"",
")",
"\n",
"return",
"pr",
".",
"Rule",
"[",
":",
"i",
"]",
"\n",
"}"
] |
// Condition returns the condition where the PluralRule applies.
|
[
"Condition",
"returns",
"the",
"condition",
"where",
"the",
"PluralRule",
"applies",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/codegen/xml.go#L45-L48
|
train
|
nicksnyder/go-i18n
|
i18n/language/codegen/xml.go
|
Examples
|
func (pr *PluralRule) Examples() (integer []string, decimal []string) {
ex := strings.Replace(pr.Rule, ", …", "", -1)
ddelim := "@decimal"
if i := strings.Index(ex, ddelim); i > 0 {
dex := strings.TrimSpace(ex[i+len(ddelim):])
decimal = strings.Split(dex, ", ")
ex = ex[:i]
}
idelim := "@integer"
if i := strings.Index(ex, idelim); i > 0 {
iex := strings.TrimSpace(ex[i+len(idelim):])
integer = strings.Split(iex, ", ")
}
return integer, decimal
}
|
go
|
func (pr *PluralRule) Examples() (integer []string, decimal []string) {
ex := strings.Replace(pr.Rule, ", …", "", -1)
ddelim := "@decimal"
if i := strings.Index(ex, ddelim); i > 0 {
dex := strings.TrimSpace(ex[i+len(ddelim):])
decimal = strings.Split(dex, ", ")
ex = ex[:i]
}
idelim := "@integer"
if i := strings.Index(ex, idelim); i > 0 {
iex := strings.TrimSpace(ex[i+len(idelim):])
integer = strings.Split(iex, ", ")
}
return integer, decimal
}
|
[
"func",
"(",
"pr",
"*",
"PluralRule",
")",
"Examples",
"(",
")",
"(",
"integer",
"[",
"]",
"string",
",",
"decimal",
"[",
"]",
"string",
")",
"{",
"ex",
":=",
"strings",
".",
"Replace",
"(",
"pr",
".",
"Rule",
",",
"\"",
" ",
"\"",
",",
" ",
"-",
")",
"",
"",
"\n",
"ddelim",
":=",
"\"",
"\"",
"\n",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"ex",
",",
"ddelim",
")",
";",
"i",
">",
"0",
"{",
"dex",
":=",
"strings",
".",
"TrimSpace",
"(",
"ex",
"[",
"i",
"+",
"len",
"(",
"ddelim",
")",
":",
"]",
")",
"\n",
"decimal",
"=",
"strings",
".",
"Split",
"(",
"dex",
",",
"\"",
"\"",
")",
"\n",
"ex",
"=",
"ex",
"[",
":",
"i",
"]",
"\n",
"}",
"\n",
"idelim",
":=",
"\"",
"\"",
"\n",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"ex",
",",
"idelim",
")",
";",
"i",
">",
"0",
"{",
"iex",
":=",
"strings",
".",
"TrimSpace",
"(",
"ex",
"[",
"i",
"+",
"len",
"(",
"idelim",
")",
":",
"]",
")",
"\n",
"integer",
"=",
"strings",
".",
"Split",
"(",
"iex",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"integer",
",",
"decimal",
"\n",
"}"
] |
// Examples returns the integer and decimal exmaples for the PLuralRule.
|
[
"Examples",
"returns",
"the",
"integer",
"and",
"decimal",
"exmaples",
"for",
"the",
"PLuralRule",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/codegen/xml.go#L51-L65
|
train
|
nicksnyder/go-i18n
|
v2/goi18n/merge_command.go
|
activeDst
|
func activeDst(src, dst *internal.MessageTemplate, pluralRule *plural.Rule) (active *internal.MessageTemplate, translateMessageTemplate *internal.MessageTemplate) {
pluralForms := pluralRule.PluralForms
if len(src.PluralTemplates) == 1 {
pluralForms = map[plural.Form]struct{}{
plural.Other: {},
}
}
for pluralForm := range pluralForms {
dt := dst.PluralTemplates[pluralForm]
if dt == nil || dt.Src == "" {
if translateMessageTemplate == nil {
translateMessageTemplate = &internal.MessageTemplate{
Message: &i18n.Message{
ID: src.ID,
Description: src.Description,
Hash: src.Hash,
},
PluralTemplates: make(map[plural.Form]*internal.Template),
}
}
translateMessageTemplate.PluralTemplates[pluralForm] = src.PluralTemplates[plural.Other]
continue
}
if active == nil {
active = &internal.MessageTemplate{
Message: &i18n.Message{
ID: src.ID,
Description: src.Description,
Hash: src.Hash,
},
PluralTemplates: make(map[plural.Form]*internal.Template),
}
}
active.PluralTemplates[pluralForm] = dt
}
return
}
|
go
|
func activeDst(src, dst *internal.MessageTemplate, pluralRule *plural.Rule) (active *internal.MessageTemplate, translateMessageTemplate *internal.MessageTemplate) {
pluralForms := pluralRule.PluralForms
if len(src.PluralTemplates) == 1 {
pluralForms = map[plural.Form]struct{}{
plural.Other: {},
}
}
for pluralForm := range pluralForms {
dt := dst.PluralTemplates[pluralForm]
if dt == nil || dt.Src == "" {
if translateMessageTemplate == nil {
translateMessageTemplate = &internal.MessageTemplate{
Message: &i18n.Message{
ID: src.ID,
Description: src.Description,
Hash: src.Hash,
},
PluralTemplates: make(map[plural.Form]*internal.Template),
}
}
translateMessageTemplate.PluralTemplates[pluralForm] = src.PluralTemplates[plural.Other]
continue
}
if active == nil {
active = &internal.MessageTemplate{
Message: &i18n.Message{
ID: src.ID,
Description: src.Description,
Hash: src.Hash,
},
PluralTemplates: make(map[plural.Form]*internal.Template),
}
}
active.PluralTemplates[pluralForm] = dt
}
return
}
|
[
"func",
"activeDst",
"(",
"src",
",",
"dst",
"*",
"internal",
".",
"MessageTemplate",
",",
"pluralRule",
"*",
"plural",
".",
"Rule",
")",
"(",
"active",
"*",
"internal",
".",
"MessageTemplate",
",",
"translateMessageTemplate",
"*",
"internal",
".",
"MessageTemplate",
")",
"{",
"pluralForms",
":=",
"pluralRule",
".",
"PluralForms",
"\n",
"if",
"len",
"(",
"src",
".",
"PluralTemplates",
")",
"==",
"1",
"{",
"pluralForms",
"=",
"map",
"[",
"plural",
".",
"Form",
"]",
"struct",
"{",
"}",
"{",
"plural",
".",
"Other",
":",
"{",
"}",
",",
"}",
"\n",
"}",
"\n",
"for",
"pluralForm",
":=",
"range",
"pluralForms",
"{",
"dt",
":=",
"dst",
".",
"PluralTemplates",
"[",
"pluralForm",
"]",
"\n",
"if",
"dt",
"==",
"nil",
"||",
"dt",
".",
"Src",
"==",
"\"",
"\"",
"{",
"if",
"translateMessageTemplate",
"==",
"nil",
"{",
"translateMessageTemplate",
"=",
"&",
"internal",
".",
"MessageTemplate",
"{",
"Message",
":",
"&",
"i18n",
".",
"Message",
"{",
"ID",
":",
"src",
".",
"ID",
",",
"Description",
":",
"src",
".",
"Description",
",",
"Hash",
":",
"src",
".",
"Hash",
",",
"}",
",",
"PluralTemplates",
":",
"make",
"(",
"map",
"[",
"plural",
".",
"Form",
"]",
"*",
"internal",
".",
"Template",
")",
",",
"}",
"\n",
"}",
"\n",
"translateMessageTemplate",
".",
"PluralTemplates",
"[",
"pluralForm",
"]",
"=",
"src",
".",
"PluralTemplates",
"[",
"plural",
".",
"Other",
"]",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"active",
"==",
"nil",
"{",
"active",
"=",
"&",
"internal",
".",
"MessageTemplate",
"{",
"Message",
":",
"&",
"i18n",
".",
"Message",
"{",
"ID",
":",
"src",
".",
"ID",
",",
"Description",
":",
"src",
".",
"Description",
",",
"Hash",
":",
"src",
".",
"Hash",
",",
"}",
",",
"PluralTemplates",
":",
"make",
"(",
"map",
"[",
"plural",
".",
"Form",
"]",
"*",
"internal",
".",
"Template",
")",
",",
"}",
"\n",
"}",
"\n",
"active",
".",
"PluralTemplates",
"[",
"pluralForm",
"]",
"=",
"dt",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// activeDst returns the active part of the dst and whether dst is a complete translation of src.
|
[
"activeDst",
"returns",
"the",
"active",
"part",
"of",
"the",
"dst",
"and",
"whether",
"dst",
"is",
"a",
"complete",
"translation",
"of",
"src",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/v2/goi18n/merge_command.go#L249-L285
|
train
|
nicksnyder/go-i18n
|
i18n/language/plural.go
|
NewPlural
|
func NewPlural(src string) (Plural, error) {
switch src {
case "zero":
return Zero, nil
case "one":
return One, nil
case "two":
return Two, nil
case "few":
return Few, nil
case "many":
return Many, nil
case "other":
return Other, nil
}
return Invalid, fmt.Errorf("invalid plural category %s", src)
}
|
go
|
func NewPlural(src string) (Plural, error) {
switch src {
case "zero":
return Zero, nil
case "one":
return One, nil
case "two":
return Two, nil
case "few":
return Few, nil
case "many":
return Many, nil
case "other":
return Other, nil
}
return Invalid, fmt.Errorf("invalid plural category %s", src)
}
|
[
"func",
"NewPlural",
"(",
"src",
"string",
")",
"(",
"Plural",
",",
"error",
")",
"{",
"switch",
"src",
"{",
"case",
"\"",
"\"",
":",
"return",
"Zero",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"One",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Two",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Few",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Many",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Other",
",",
"nil",
"\n",
"}",
"\n",
"return",
"Invalid",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"src",
")",
"\n",
"}"
] |
// NewPlural returns src as a Plural
// or Invalid and a non-nil error if src is not a valid Plural.
|
[
"NewPlural",
"returns",
"src",
"as",
"a",
"Plural",
"or",
"Invalid",
"and",
"a",
"non",
"-",
"nil",
"error",
"if",
"src",
"is",
"not",
"a",
"valid",
"Plural",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/language/plural.go#L24-L40
|
train
|
nicksnyder/go-i18n
|
i18n/bundle/bundle.go
|
New
|
func New() *Bundle {
return &Bundle{
translations: make(map[string]map[string]translation.Translation),
fallbackTranslations: make(map[string]map[string]translation.Translation),
}
}
|
go
|
func New() *Bundle {
return &Bundle{
translations: make(map[string]map[string]translation.Translation),
fallbackTranslations: make(map[string]map[string]translation.Translation),
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Bundle",
"{",
"return",
"&",
"Bundle",
"{",
"translations",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"translation",
".",
"Translation",
")",
",",
"fallbackTranslations",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"translation",
".",
"Translation",
")",
",",
"}",
"\n",
"}"
] |
// New returns an empty bundle.
|
[
"New",
"returns",
"an",
"empty",
"bundle",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/bundle/bundle.go#L35-L40
|
train
|
nicksnyder/go-i18n
|
i18n/bundle/bundle.go
|
MustLoadTranslationFile
|
func (b *Bundle) MustLoadTranslationFile(filename string) {
if err := b.LoadTranslationFile(filename); err != nil {
panic(err)
}
}
|
go
|
func (b *Bundle) MustLoadTranslationFile(filename string) {
if err := b.LoadTranslationFile(filename); err != nil {
panic(err)
}
}
|
[
"func",
"(",
"b",
"*",
"Bundle",
")",
"MustLoadTranslationFile",
"(",
"filename",
"string",
")",
"{",
"if",
"err",
":=",
"b",
".",
"LoadTranslationFile",
"(",
"filename",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// MustLoadTranslationFile is similar to LoadTranslationFile
// except it panics if an error happens.
|
[
"MustLoadTranslationFile",
"is",
"similar",
"to",
"LoadTranslationFile",
"except",
"it",
"panics",
"if",
"an",
"error",
"happens",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/bundle/bundle.go#L44-L48
|
train
|
nicksnyder/go-i18n
|
i18n/bundle/bundle.go
|
deleteLeadingComments
|
func deleteLeadingComments(ext string, buf []byte) []byte {
if ext != ".yaml" {
return buf
}
for {
buf = bytes.TrimLeftFunc(buf, unicode.IsSpace)
if buf[0] == '#' {
buf = deleteLine(buf)
} else {
break
}
}
return buf
}
|
go
|
func deleteLeadingComments(ext string, buf []byte) []byte {
if ext != ".yaml" {
return buf
}
for {
buf = bytes.TrimLeftFunc(buf, unicode.IsSpace)
if buf[0] == '#' {
buf = deleteLine(buf)
} else {
break
}
}
return buf
}
|
[
"func",
"deleteLeadingComments",
"(",
"ext",
"string",
",",
"buf",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"ext",
"!=",
"\"",
"\"",
"{",
"return",
"buf",
"\n",
"}",
"\n\n",
"for",
"{",
"buf",
"=",
"bytes",
".",
"TrimLeftFunc",
"(",
"buf",
",",
"unicode",
".",
"IsSpace",
")",
"\n",
"if",
"buf",
"[",
"0",
"]",
"==",
"'#'",
"{",
"buf",
"=",
"deleteLine",
"(",
"buf",
")",
"\n",
"}",
"else",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"buf",
"\n",
"}"
] |
// deleteLeadingComments deletes leading newlines and comments in buf.
// It only works for ext == ".yaml".
|
[
"deleteLeadingComments",
"deletes",
"leading",
"newlines",
"and",
"comments",
"in",
"buf",
".",
"It",
"only",
"works",
"for",
"ext",
"==",
".",
"yaml",
"."
] |
b2843f1401bcdec49ebbd5b729689ee36ea1e65a
|
https://github.com/nicksnyder/go-i18n/blob/b2843f1401bcdec49ebbd5b729689ee36ea1e65a/i18n/bundle/bundle.go#L129-L144
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.