id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
14,700
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetTimeoutAction
func (o *ProvisioningTimeout) SetTimeoutAction(v *string) *ProvisioningTimeout { if o.TimeoutAction = v; o.TimeoutAction == nil { o.nullFields = append(o.nullFields, "TimeoutAction") } return o }
go
func (o *ProvisioningTimeout) SetTimeoutAction(v *string) *ProvisioningTimeout { if o.TimeoutAction = v; o.TimeoutAction == nil { o.nullFields = append(o.nullFields, "TimeoutAction") } return o }
[ "func", "(", "o", "*", "ProvisioningTimeout", ")", "SetTimeoutAction", "(", "v", "*", "string", ")", "*", "ProvisioningTimeout", "{", "if", "o", ".", "TimeoutAction", "=", "v", ";", "o", ".", "TimeoutAction", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetTimeoutAction sets the action to take on timeout
[ "SetTimeoutAction", "sets", "the", "action", "to", "take", "on", "timeout" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L802-L807
14,701
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetBootstrapActions
func (o *Compute) SetBootstrapActions(v *BootstrapActions) *Compute { if o.BootstrapActions = v; o.BootstrapActions == nil { o.nullFields = append(o.nullFields, "BootstrapActions") } return o }
go
func (o *Compute) SetBootstrapActions(v *BootstrapActions) *Compute { if o.BootstrapActions = v; o.BootstrapActions == nil { o.nullFields = append(o.nullFields, "BootstrapActions") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetBootstrapActions", "(", "v", "*", "BootstrapActions", ")", "*", "Compute", "{", "if", "o", ".", "BootstrapActions", "=", "v", ";", "o", ".", "BootstrapActions", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetBootstrapActions sets the path for a bootstrap actions file stored in AWS S3
[ "SetBootstrapActions", "sets", "the", "path", "for", "a", "bootstrap", "actions", "file", "stored", "in", "AWS", "S3" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L852-L857
14,702
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetSteps
func (o *Compute) SetSteps(v *Steps) *Compute { if o.Steps = v; o.Steps == nil { o.nullFields = append(o.nullFields, "Steps") } return o }
go
func (o *Compute) SetSteps(v *Steps) *Compute { if o.Steps = v; o.Steps == nil { o.nullFields = append(o.nullFields, "Steps") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetSteps", "(", "v", "*", "Steps", ")", "*", "Compute", "{", "if", "o", ".", "Steps", "=", "v", ";", "o", ".", "Steps", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetSteps sets the path for a steps file stored in AWS S3
[ "SetSteps", "sets", "the", "path", "for", "a", "steps", "file", "stored", "in", "AWS", "S3" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L860-L865
14,703
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetEBSRootVolumeSize
func (o *Compute) SetEBSRootVolumeSize(v *int) *Compute { if o.EBSRootVolumeSize = v; o.EBSRootVolumeSize == nil { o.nullFields = append(o.nullFields, "EBSRootVolumeSize") } return o }
go
func (o *Compute) SetEBSRootVolumeSize(v *int) *Compute { if o.EBSRootVolumeSize = v; o.EBSRootVolumeSize == nil { o.nullFields = append(o.nullFields, "EBSRootVolumeSize") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetEBSRootVolumeSize", "(", "v", "*", "int", ")", "*", "Compute", "{", "if", "o", ".", "EBSRootVolumeSize", "=", "v", ";", "o", ".", "EBSRootVolumeSize", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetEBSRootVolumeSize sets the ebs root volume size when creating a new scaler
[ "SetEBSRootVolumeSize", "sets", "the", "ebs", "root", "volume", "size", "when", "creating", "a", "new", "scaler" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L868-L873
14,704
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetManagedPrimarySecurityGroup
func (o *Compute) SetManagedPrimarySecurityGroup(v *string) *Compute { if o.ManagedPrimarySecurityGroup = v; o.ManagedPrimarySecurityGroup == nil { o.nullFields = append(o.nullFields, "ManagedPrimarySecurityGroup") } return o }
go
func (o *Compute) SetManagedPrimarySecurityGroup(v *string) *Compute { if o.ManagedPrimarySecurityGroup = v; o.ManagedPrimarySecurityGroup == nil { o.nullFields = append(o.nullFields, "ManagedPrimarySecurityGroup") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetManagedPrimarySecurityGroup", "(", "v", "*", "string", ")", "*", "Compute", "{", "if", "o", ".", "ManagedPrimarySecurityGroup", "=", "v", ";", "o", ".", "ManagedPrimarySecurityGroup", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetManagedPrimarySecurityGroup sets the managed primary security group when creating a new scaler
[ "SetManagedPrimarySecurityGroup", "sets", "the", "managed", "primary", "security", "group", "when", "creating", "a", "new", "scaler" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L876-L881
14,705
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetManagedReplicaSecurityGroup
func (o *Compute) SetManagedReplicaSecurityGroup(v *string) *Compute { if o.ManagedReplicaSecurityGroup = v; o.ManagedReplicaSecurityGroup == nil { o.nullFields = append(o.nullFields, "ManagedReplicaSecurityGroup") } return o }
go
func (o *Compute) SetManagedReplicaSecurityGroup(v *string) *Compute { if o.ManagedReplicaSecurityGroup = v; o.ManagedReplicaSecurityGroup == nil { o.nullFields = append(o.nullFields, "ManagedReplicaSecurityGroup") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetManagedReplicaSecurityGroup", "(", "v", "*", "string", ")", "*", "Compute", "{", "if", "o", ".", "ManagedReplicaSecurityGroup", "=", "v", ";", "o", ".", "ManagedReplicaSecurityGroup", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetManagedReplicaSecurityGroup sets the managed replica security group when creating a new scaler
[ "SetManagedReplicaSecurityGroup", "sets", "the", "managed", "replica", "security", "group", "when", "creating", "a", "new", "scaler" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L884-L889
14,706
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetServiceAccessSecurityGroup
func (o *Compute) SetServiceAccessSecurityGroup(v *string) *Compute { if o.ServiceAccessSecurityGroup = v; o.ServiceAccessSecurityGroup == nil { o.nullFields = append(o.nullFields, "ServiceAccessSecurityGroup") } return o }
go
func (o *Compute) SetServiceAccessSecurityGroup(v *string) *Compute { if o.ServiceAccessSecurityGroup = v; o.ServiceAccessSecurityGroup == nil { o.nullFields = append(o.nullFields, "ServiceAccessSecurityGroup") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetServiceAccessSecurityGroup", "(", "v", "*", "string", ")", "*", "Compute", "{", "if", "o", ".", "ServiceAccessSecurityGroup", "=", "v", ";", "o", ".", "ServiceAccessSecurityGroup", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetServiceAccessSecurityGroup sets the service security group when creating a new scaler
[ "SetServiceAccessSecurityGroup", "sets", "the", "service", "security", "group", "when", "creating", "a", "new", "scaler" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L892-L897
14,707
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetAdditionalPrimarySecurityGroups
func (o *Compute) SetAdditionalPrimarySecurityGroups(v []string) *Compute { if o.AdditionalPrimarySecurityGroups = v; o.AdditionalPrimarySecurityGroups == nil { o.nullFields = append(o.nullFields, "AdditionalPrimarySecurityGroups") } return o }
go
func (o *Compute) SetAdditionalPrimarySecurityGroups(v []string) *Compute { if o.AdditionalPrimarySecurityGroups = v; o.AdditionalPrimarySecurityGroups == nil { o.nullFields = append(o.nullFields, "AdditionalPrimarySecurityGroups") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetAdditionalPrimarySecurityGroups", "(", "v", "[", "]", "string", ")", "*", "Compute", "{", "if", "o", ".", "AdditionalPrimarySecurityGroups", "=", "v", ";", "o", ".", "AdditionalPrimarySecurityGroups", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetAdditionalPrimarySecurityGroups sets a list of additional primary security groups
[ "SetAdditionalPrimarySecurityGroups", "sets", "a", "list", "of", "additional", "primary", "security", "groups" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L900-L905
14,708
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetAdditionalReplicaSecurityGroups
func (o *Compute) SetAdditionalReplicaSecurityGroups(v []string) *Compute { if o.AdditionalReplicaSecurityGroups = v; o.AdditionalReplicaSecurityGroups == nil { o.nullFields = append(o.nullFields, "AdditionalReplicaSecurityGroups") } return o }
go
func (o *Compute) SetAdditionalReplicaSecurityGroups(v []string) *Compute { if o.AdditionalReplicaSecurityGroups = v; o.AdditionalReplicaSecurityGroups == nil { o.nullFields = append(o.nullFields, "AdditionalReplicaSecurityGroups") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetAdditionalReplicaSecurityGroups", "(", "v", "[", "]", "string", ")", "*", "Compute", "{", "if", "o", ".", "AdditionalReplicaSecurityGroups", "=", "v", ";", "o", ".", "AdditionalReplicaSecurityGroups", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetAdditionalReplicaSecurityGroups sets a list of additional Replica security groups
[ "SetAdditionalReplicaSecurityGroups", "sets", "a", "list", "of", "additional", "Replica", "security", "groups" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L908-L913
14,709
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetCustomAMIID
func (o *Compute) SetCustomAMIID(v *string) *Compute { if o.CustomAMIID = v; o.CustomAMIID == nil { o.nullFields = append(o.nullFields, "CustomAMIID") } return o }
go
func (o *Compute) SetCustomAMIID(v *string) *Compute { if o.CustomAMIID = v; o.CustomAMIID == nil { o.nullFields = append(o.nullFields, "CustomAMIID") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetCustomAMIID", "(", "v", "*", "string", ")", "*", "Compute", "{", "if", "o", ".", "CustomAMIID", "=", "v", ";", "o", ".", "CustomAMIID", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetCustomAMIID sets the custom AMI ID
[ "SetCustomAMIID", "sets", "the", "custom", "AMI", "ID" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L916-L921
14,710
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetEC2KeyName
func (o *Compute) SetEC2KeyName(v *string) *Compute { if o.EC2KeyName = v; o.EC2KeyName == nil { o.nullFields = append(o.nullFields, "EC2KeyName") } return o }
go
func (o *Compute) SetEC2KeyName(v *string) *Compute { if o.EC2KeyName = v; o.EC2KeyName == nil { o.nullFields = append(o.nullFields, "EC2KeyName") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetEC2KeyName", "(", "v", "*", "string", ")", "*", "Compute", "{", "if", "o", ".", "EC2KeyName", "=", "v", ";", "o", ".", "EC2KeyName", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetEC2KeyName sets the EC2 key name
[ "SetEC2KeyName", "sets", "the", "EC2", "key", "name" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L931-L936
14,711
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetApplications
func (o *Compute) SetApplications(v []*Application) *Compute { if o.Applications = v; o.Applications == nil { o.nullFields = append(o.nullFields, "Applications") } return o }
go
func (o *Compute) SetApplications(v []*Application) *Compute { if o.Applications = v; o.Applications == nil { o.nullFields = append(o.nullFields, "Applications") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetApplications", "(", "v", "[", "]", "*", "Application", ")", "*", "Compute", "{", "if", "o", ".", "Applications", "=", "v", ";", "o", ".", "Applications", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetApplications sets the applications object
[ "SetApplications", "sets", "the", "applications", "object" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L939-L944
14,712
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetInstanceWeights
func (o *Compute) SetInstanceWeights(v []*InstanceWeight) *Compute { if o.InstanceWeights = v; o.InstanceWeights == nil { o.nullFields = append(o.nullFields, "InstanceWeights") } return o }
go
func (o *Compute) SetInstanceWeights(v []*InstanceWeight) *Compute { if o.InstanceWeights = v; o.InstanceWeights == nil { o.nullFields = append(o.nullFields, "InstanceWeights") } return o }
[ "func", "(", "o", "*", "Compute", ")", "SetInstanceWeights", "(", "v", "[", "]", "*", "InstanceWeight", ")", "*", "Compute", "{", "if", "o", ".", "InstanceWeights", "=", "v", ";", "o", ".", "InstanceWeights", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetInstanceWeights sets a list if instance weights by type
[ "SetInstanceWeights", "sets", "a", "list", "if", "instance", "weights", "by", "type" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L947-L952
14,713
spotinst/spotinst-sdk-go
service/mrscaler/mrscaler.go
SetArgs
func (o *Application) SetArgs(v []string) *Application { if o.Args = v; o.Args == nil { o.nullFields = append(o.nullFields, "Args") } return o }
go
func (o *Application) SetArgs(v []string) *Application { if o.Args = v; o.Args == nil { o.nullFields = append(o.nullFields, "Args") } return o }
[ "func", "(", "o", "*", "Application", ")", "SetArgs", "(", "v", "[", "]", "string", ")", "*", "Application", "{", "if", "o", ".", "Args", "=", "v", ";", "o", ".", "Args", "==", "nil", "{", "o", ".", "nullFields", "=", "append", "(", "o", ".", "nullFields", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "o", "\n", "}" ]
// SetArgs sets the list of args to use with the application
[ "SetArgs", "sets", "the", "list", "of", "args", "to", "use", "with", "the", "application" ]
8cd52da677ef8425428ef610f0243863759639c8
https://github.com/spotinst/spotinst-sdk-go/blob/8cd52da677ef8425428ef610f0243863759639c8/service/mrscaler/mrscaler.go#L965-L970
14,714
aanand/compose-file
template/template.go
partition
func partition(s, sep string) (string, string) { if strings.Contains(s, sep) { parts := strings.SplitN(s, sep, 2) return parts[0], parts[1] } else { return s, "" } }
go
func partition(s, sep string) (string, string) { if strings.Contains(s, sep) { parts := strings.SplitN(s, sep, 2) return parts[0], parts[1] } else { return s, "" } }
[ "func", "partition", "(", "s", ",", "sep", "string", ")", "(", "string", ",", "string", ")", "{", "if", "strings", ".", "Contains", "(", "s", ",", "sep", ")", "{", "parts", ":=", "strings", ".", "SplitN", "(", "s", ",", "sep", ",", "2", ")", "\n", "return", "parts", "[", "0", "]", ",", "parts", "[", "1", "]", "\n", "}", "else", "{", "return", "s", ",", "\"", "\"", "\n", "}", "\n", "}" ]
// Split the string at the first occurrence of sep, and return the part before the separator, // and the part after the separator. // // If the separator is not found, return the string itself, followed by an empty string.
[ "Split", "the", "string", "at", "the", "first", "occurrence", "of", "sep", "and", "return", "the", "part", "before", "the", "separator", "and", "the", "part", "after", "the", "separator", ".", "If", "the", "separator", "is", "not", "found", "return", "the", "string", "itself", "followed", "by", "an", "empty", "string", "." ]
8b762b24ea40ea5ceda5aac2dd1cd465d0fe6d42
https://github.com/aanand/compose-file/blob/8b762b24ea40ea5ceda5aac2dd1cd465d0fe6d42/template/template.go#L101-L108
14,715
DavidHuie/gomigrate
utils.go
parseMigrationPath
func parseMigrationPath(path string) (uint64, migrationType, string, error) { filebase := filepath.Base(path) matches := upMigrationFile.FindAllSubmatch([]byte(filebase), -1) if matches != nil { return parseMatches(matches, upMigration) } matches = downMigrationFile.FindAllSubmatch([]byte(filebase), -1) if matches != nil { return parseMatches(matches, downMigration) } return 0, "", "", InvalidMigrationFile }
go
func parseMigrationPath(path string) (uint64, migrationType, string, error) { filebase := filepath.Base(path) matches := upMigrationFile.FindAllSubmatch([]byte(filebase), -1) if matches != nil { return parseMatches(matches, upMigration) } matches = downMigrationFile.FindAllSubmatch([]byte(filebase), -1) if matches != nil { return parseMatches(matches, downMigration) } return 0, "", "", InvalidMigrationFile }
[ "func", "parseMigrationPath", "(", "path", "string", ")", "(", "uint64", ",", "migrationType", ",", "string", ",", "error", ")", "{", "filebase", ":=", "filepath", ".", "Base", "(", "path", ")", "\n\n", "matches", ":=", "upMigrationFile", ".", "FindAllSubmatch", "(", "[", "]", "byte", "(", "filebase", ")", ",", "-", "1", ")", "\n", "if", "matches", "!=", "nil", "{", "return", "parseMatches", "(", "matches", ",", "upMigration", ")", "\n", "}", "\n", "matches", "=", "downMigrationFile", ".", "FindAllSubmatch", "(", "[", "]", "byte", "(", "filebase", ")", ",", "-", "1", ")", "\n", "if", "matches", "!=", "nil", "{", "return", "parseMatches", "(", "matches", ",", "downMigration", ")", "\n", "}", "\n\n", "return", "0", ",", "\"", "\"", ",", "\"", "\"", ",", "InvalidMigrationFile", "\n", "}" ]
// Returns the migration number, type and base name, so 1, "up", "migration" from "01_migration_up.sql"
[ "Returns", "the", "migration", "number", "type", "and", "base", "name", "so", "1", "up", "migration", "from", "01_migration_up", ".", "sql" ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/utils.go#L17-L30
14,716
DavidHuie/gomigrate
utils.go
parseMatches
func parseMatches(matches [][][]byte, mType migrationType) (uint64, migrationType, string, error) { num := matches[0][1] name := matches[0][2] parsedNum, err := strconv.ParseUint(string(num), 10, 64) if err != nil { return 0, "", "", err } return parsedNum, mType, string(name), nil }
go
func parseMatches(matches [][][]byte, mType migrationType) (uint64, migrationType, string, error) { num := matches[0][1] name := matches[0][2] parsedNum, err := strconv.ParseUint(string(num), 10, 64) if err != nil { return 0, "", "", err } return parsedNum, mType, string(name), nil }
[ "func", "parseMatches", "(", "matches", "[", "]", "[", "]", "[", "]", "byte", ",", "mType", "migrationType", ")", "(", "uint64", ",", "migrationType", ",", "string", ",", "error", ")", "{", "num", ":=", "matches", "[", "0", "]", "[", "1", "]", "\n", "name", ":=", "matches", "[", "0", "]", "[", "2", "]", "\n", "parsedNum", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "string", "(", "num", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "parsedNum", ",", "mType", ",", "string", "(", "name", ")", ",", "nil", "\n", "}" ]
// Parses matches given by a migration file regex.
[ "Parses", "matches", "given", "by", "a", "migration", "file", "regex", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/utils.go#L33-L41
14,717
DavidHuie/gomigrate
migration.go
valid
func (m *Migration) valid() bool { if m.Id != 0 && m.Name != "" && m.UpPath != "" && m.DownPath != "" { return true } return false }
go
func (m *Migration) valid() bool { if m.Id != 0 && m.Name != "" && m.UpPath != "" && m.DownPath != "" { return true } return false }
[ "func", "(", "m", "*", "Migration", ")", "valid", "(", ")", "bool", "{", "if", "m", ".", "Id", "!=", "0", "&&", "m", ".", "Name", "!=", "\"", "\"", "&&", "m", ".", "UpPath", "!=", "\"", "\"", "&&", "m", ".", "DownPath", "!=", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Performs a basic validation of a migration.
[ "Performs", "a", "basic", "validation", "of", "a", "migration", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/migration.go#L21-L26
14,718
DavidHuie/gomigrate
gomigrate.go
MigrationTableExists
func (m *Migrator) MigrationTableExists() (bool, error) { row := m.DB.QueryRow(m.dbAdapter.SelectMigrationTableSql(), migrationTableName) var tableName string err := row.Scan(&tableName) if err == sql.ErrNoRows { m.logger.Print("Migrations table not found") return false, nil } if err != nil { m.logger.Printf("Error checking for migration table: %v", err) return false, err } m.logger.Print("Migrations table found") return true, nil }
go
func (m *Migrator) MigrationTableExists() (bool, error) { row := m.DB.QueryRow(m.dbAdapter.SelectMigrationTableSql(), migrationTableName) var tableName string err := row.Scan(&tableName) if err == sql.ErrNoRows { m.logger.Print("Migrations table not found") return false, nil } if err != nil { m.logger.Printf("Error checking for migration table: %v", err) return false, err } m.logger.Print("Migrations table found") return true, nil }
[ "func", "(", "m", "*", "Migrator", ")", "MigrationTableExists", "(", ")", "(", "bool", ",", "error", ")", "{", "row", ":=", "m", ".", "DB", ".", "QueryRow", "(", "m", ".", "dbAdapter", ".", "SelectMigrationTableSql", "(", ")", ",", "migrationTableName", ")", "\n", "var", "tableName", "string", "\n", "err", ":=", "row", ".", "Scan", "(", "&", "tableName", ")", "\n", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "m", ".", "logger", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "false", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "false", ",", "err", "\n", "}", "\n", "m", ".", "logger", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "true", ",", "nil", "\n", "}" ]
// Returns true if the migration table already exists.
[ "Returns", "true", "if", "the", "migration", "table", "already", "exists", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L47-L61
14,719
DavidHuie/gomigrate
gomigrate.go
CreateMigrationsTable
func (m *Migrator) CreateMigrationsTable() error { _, err := m.DB.Exec(m.dbAdapter.CreateMigrationTableSql()) if err != nil { m.logger.Fatalf("Error creating migrations table: %v", err) } m.logger.Printf("Created migrations table: %s", migrationTableName) return nil }
go
func (m *Migrator) CreateMigrationsTable() error { _, err := m.DB.Exec(m.dbAdapter.CreateMigrationTableSql()) if err != nil { m.logger.Fatalf("Error creating migrations table: %v", err) } m.logger.Printf("Created migrations table: %s", migrationTableName) return nil }
[ "func", "(", "m", "*", "Migrator", ")", "CreateMigrationsTable", "(", ")", "error", "{", "_", ",", "err", ":=", "m", ".", "DB", ".", "Exec", "(", "m", ".", "dbAdapter", ".", "CreateMigrationTableSql", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "migrationTableName", ")", "\n\n", "return", "nil", "\n", "}" ]
// Creates the migrations table if it doesn't exist.
[ "Creates", "the", "migrations", "table", "if", "it", "doesn", "t", "exist", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L64-L73
14,720
DavidHuie/gomigrate
gomigrate.go
NewMigrator
func NewMigrator(db *sql.DB, adapter Migratable, migrationsPath string) (*Migrator, error) { return NewMigratorWithLogger(db, adapter, migrationsPath, log.New(os.Stderr, "[gomigrate] ", log.LstdFlags)) }
go
func NewMigrator(db *sql.DB, adapter Migratable, migrationsPath string) (*Migrator, error) { return NewMigratorWithLogger(db, adapter, migrationsPath, log.New(os.Stderr, "[gomigrate] ", log.LstdFlags)) }
[ "func", "NewMigrator", "(", "db", "*", "sql", ".", "DB", ",", "adapter", "Migratable", ",", "migrationsPath", "string", ")", "(", "*", "Migrator", ",", "error", ")", "{", "return", "NewMigratorWithLogger", "(", "db", ",", "adapter", ",", "migrationsPath", ",", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "log", ".", "LstdFlags", ")", ")", "\n", "}" ]
// Returns a new migrator.
[ "Returns", "a", "new", "migrator", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L76-L78
14,721
DavidHuie/gomigrate
gomigrate.go
NewMigratorWithLogger
func NewMigratorWithLogger(db *sql.DB, adapter Migratable, migrationsPath string, logger Logger) (*Migrator, error) { // Normalize the migrations path. path := []byte(migrationsPath) pathLength := len(path) if path[pathLength-1] != '/' { path = append(path, '/') } logger.Printf("Migrations path: %s", path) migrator := Migrator{ db, string(path), adapter, make(map[uint64]*Migration), logger, } // Create the migrations table if it doesn't exist. tableExists, err := migrator.MigrationTableExists() if err != nil { return nil, err } if !tableExists { if err := migrator.CreateMigrationsTable(); err != nil { return nil, err } } // Get all metadata from the database. if err := migrator.fetchMigrations(); err != nil { return nil, err } if err := migrator.getMigrationStatuses(); err != nil { return nil, err } return &migrator, nil }
go
func NewMigratorWithLogger(db *sql.DB, adapter Migratable, migrationsPath string, logger Logger) (*Migrator, error) { // Normalize the migrations path. path := []byte(migrationsPath) pathLength := len(path) if path[pathLength-1] != '/' { path = append(path, '/') } logger.Printf("Migrations path: %s", path) migrator := Migrator{ db, string(path), adapter, make(map[uint64]*Migration), logger, } // Create the migrations table if it doesn't exist. tableExists, err := migrator.MigrationTableExists() if err != nil { return nil, err } if !tableExists { if err := migrator.CreateMigrationsTable(); err != nil { return nil, err } } // Get all metadata from the database. if err := migrator.fetchMigrations(); err != nil { return nil, err } if err := migrator.getMigrationStatuses(); err != nil { return nil, err } return &migrator, nil }
[ "func", "NewMigratorWithLogger", "(", "db", "*", "sql", ".", "DB", ",", "adapter", "Migratable", ",", "migrationsPath", "string", ",", "logger", "Logger", ")", "(", "*", "Migrator", ",", "error", ")", "{", "// Normalize the migrations path.", "path", ":=", "[", "]", "byte", "(", "migrationsPath", ")", "\n", "pathLength", ":=", "len", "(", "path", ")", "\n", "if", "path", "[", "pathLength", "-", "1", "]", "!=", "'/'", "{", "path", "=", "append", "(", "path", ",", "'/'", ")", "\n", "}", "\n\n", "logger", ".", "Printf", "(", "\"", "\"", ",", "path", ")", "\n\n", "migrator", ":=", "Migrator", "{", "db", ",", "string", "(", "path", ")", ",", "adapter", ",", "make", "(", "map", "[", "uint64", "]", "*", "Migration", ")", ",", "logger", ",", "}", "\n\n", "// Create the migrations table if it doesn't exist.", "tableExists", ",", "err", ":=", "migrator", ".", "MigrationTableExists", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "tableExists", "{", "if", "err", ":=", "migrator", ".", "CreateMigrationsTable", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "// Get all metadata from the database.", "if", "err", ":=", "migrator", ".", "fetchMigrations", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "migrator", ".", "getMigrationStatuses", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "migrator", ",", "nil", "\n", "}" ]
// Returns a new migrator with the specified logger.
[ "Returns", "a", "new", "migrator", "with", "the", "specified", "logger", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L81-L119
14,722
DavidHuie/gomigrate
gomigrate.go
fetchMigrations
func (m *Migrator) fetchMigrations() error { pathGlob := append([]byte(m.MigrationsPath), []byte("*")...) matches, err := filepath.Glob(string(pathGlob)) if err != nil { m.logger.Fatalf("Error while globbing migrations: %v", err) } for _, match := range matches { num, migrationType, name, err := parseMigrationPath(match) if err != nil { m.logger.Printf("Invalid migration file found: %s", match) continue } m.logger.Printf("Migration file found: %s", match) migration, ok := m.migrations[num] if !ok { migration = &Migration{Id: num, Name: name, Status: Inactive} m.migrations[num] = migration } if migrationType == upMigration { migration.UpPath = match } else { migration.DownPath = match } } // Validate each migration. for _, migration := range m.migrations { if !migration.valid() { path := migration.UpPath if path == "" { path = migration.DownPath } m.logger.Printf("Invalid migration pair for path: %s", path) return InvalidMigrationPair } } m.logger.Printf("Migrations file pairs found: %v", len(m.migrations)) return nil }
go
func (m *Migrator) fetchMigrations() error { pathGlob := append([]byte(m.MigrationsPath), []byte("*")...) matches, err := filepath.Glob(string(pathGlob)) if err != nil { m.logger.Fatalf("Error while globbing migrations: %v", err) } for _, match := range matches { num, migrationType, name, err := parseMigrationPath(match) if err != nil { m.logger.Printf("Invalid migration file found: %s", match) continue } m.logger.Printf("Migration file found: %s", match) migration, ok := m.migrations[num] if !ok { migration = &Migration{Id: num, Name: name, Status: Inactive} m.migrations[num] = migration } if migrationType == upMigration { migration.UpPath = match } else { migration.DownPath = match } } // Validate each migration. for _, migration := range m.migrations { if !migration.valid() { path := migration.UpPath if path == "" { path = migration.DownPath } m.logger.Printf("Invalid migration pair for path: %s", path) return InvalidMigrationPair } } m.logger.Printf("Migrations file pairs found: %v", len(m.migrations)) return nil }
[ "func", "(", "m", "*", "Migrator", ")", "fetchMigrations", "(", ")", "error", "{", "pathGlob", ":=", "append", "(", "[", "]", "byte", "(", "m", ".", "MigrationsPath", ")", ",", "[", "]", "byte", "(", "\"", "\"", ")", "...", ")", "\n\n", "matches", ",", "err", ":=", "filepath", ".", "Glob", "(", "string", "(", "pathGlob", ")", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "match", ":=", "range", "matches", "{", "num", ",", "migrationType", ",", "name", ",", "err", ":=", "parseMigrationPath", "(", "match", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "match", ")", "\n", "continue", "\n", "}", "\n\n", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "match", ")", "\n\n", "migration", ",", "ok", ":=", "m", ".", "migrations", "[", "num", "]", "\n", "if", "!", "ok", "{", "migration", "=", "&", "Migration", "{", "Id", ":", "num", ",", "Name", ":", "name", ",", "Status", ":", "Inactive", "}", "\n", "m", ".", "migrations", "[", "num", "]", "=", "migration", "\n", "}", "\n", "if", "migrationType", "==", "upMigration", "{", "migration", ".", "UpPath", "=", "match", "\n", "}", "else", "{", "migration", ".", "DownPath", "=", "match", "\n", "}", "\n", "}", "\n\n", "// Validate each migration.", "for", "_", ",", "migration", ":=", "range", "m", ".", "migrations", "{", "if", "!", "migration", ".", "valid", "(", ")", "{", "path", ":=", "migration", ".", "UpPath", "\n", "if", "path", "==", "\"", "\"", "{", "path", "=", "migration", ".", "DownPath", "\n", "}", "\n", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "path", ")", "\n", "return", "InvalidMigrationPair", "\n", "}", "\n", "}", "\n\n", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "len", "(", "m", ".", "migrations", ")", ")", "\n\n", "return", "nil", "\n", "}" ]
// Populates a migrator with a sorted list of migrations from the file system.
[ "Populates", "a", "migrator", "with", "a", "sorted", "list", "of", "migrations", "from", "the", "file", "system", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L122-L166
14,723
DavidHuie/gomigrate
gomigrate.go
getMigrationStatuses
func (m *Migrator) getMigrationStatuses() error { for _, migration := range m.migrations { row := m.DB.QueryRow(m.dbAdapter.GetMigrationSql(), migration.Id) var mid uint64 err := row.Scan(&mid) if err == sql.ErrNoRows { continue } if err != nil { m.logger.Printf( "Error getting migration status for %s: %v", migration.Name, err, ) return err } migration.Status = Active } return nil }
go
func (m *Migrator) getMigrationStatuses() error { for _, migration := range m.migrations { row := m.DB.QueryRow(m.dbAdapter.GetMigrationSql(), migration.Id) var mid uint64 err := row.Scan(&mid) if err == sql.ErrNoRows { continue } if err != nil { m.logger.Printf( "Error getting migration status for %s: %v", migration.Name, err, ) return err } migration.Status = Active } return nil }
[ "func", "(", "m", "*", "Migrator", ")", "getMigrationStatuses", "(", ")", "error", "{", "for", "_", ",", "migration", ":=", "range", "m", ".", "migrations", "{", "row", ":=", "m", ".", "DB", ".", "QueryRow", "(", "m", ".", "dbAdapter", ".", "GetMigrationSql", "(", ")", ",", "migration", ".", "Id", ")", "\n", "var", "mid", "uint64", "\n", "err", ":=", "row", ".", "Scan", "(", "&", "mid", ")", "\n", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "migration", ".", "Name", ",", "err", ",", ")", "\n", "return", "err", "\n", "}", "\n", "migration", ".", "Status", "=", "Active", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Queries the migration table to determine the status of each // migration.
[ "Queries", "the", "migration", "table", "to", "determine", "the", "status", "of", "each", "migration", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L170-L189
14,724
DavidHuie/gomigrate
gomigrate.go
Migrations
func (m *Migrator) Migrations(status int) []*Migration { // Sort all migration ids. ids := make([]uint64, 0) for id, _ := range m.migrations { ids = append(ids, id) } sort.Sort(uint64slice(ids)) // Find ids for the given status. migrations := make([]*Migration, 0) for _, id := range ids { migration := m.migrations[id] if status == -1 || migration.Status == status { migrations = append(migrations, migration) } } return migrations }
go
func (m *Migrator) Migrations(status int) []*Migration { // Sort all migration ids. ids := make([]uint64, 0) for id, _ := range m.migrations { ids = append(ids, id) } sort.Sort(uint64slice(ids)) // Find ids for the given status. migrations := make([]*Migration, 0) for _, id := range ids { migration := m.migrations[id] if status == -1 || migration.Status == status { migrations = append(migrations, migration) } } return migrations }
[ "func", "(", "m", "*", "Migrator", ")", "Migrations", "(", "status", "int", ")", "[", "]", "*", "Migration", "{", "// Sort all migration ids.", "ids", ":=", "make", "(", "[", "]", "uint64", ",", "0", ")", "\n", "for", "id", ",", "_", ":=", "range", "m", ".", "migrations", "{", "ids", "=", "append", "(", "ids", ",", "id", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "uint64slice", "(", "ids", ")", ")", "\n\n", "// Find ids for the given status.", "migrations", ":=", "make", "(", "[", "]", "*", "Migration", ",", "0", ")", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "migration", ":=", "m", ".", "migrations", "[", "id", "]", "\n", "if", "status", "==", "-", "1", "||", "migration", ".", "Status", "==", "status", "{", "migrations", "=", "append", "(", "migrations", ",", "migration", ")", "\n", "}", "\n", "}", "\n", "return", "migrations", "\n", "}" ]
// Returns a sorted list of migration ids for a given status. -1 returns // all migrations.
[ "Returns", "a", "sorted", "list", "of", "migration", "ids", "for", "a", "given", "status", ".", "-", "1", "returns", "all", "migrations", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L193-L210
14,725
DavidHuie/gomigrate
gomigrate.go
ApplyMigration
func (m *Migrator) ApplyMigration(migration *Migration, mType migrationType) error { var path string if mType == upMigration { path = migration.UpPath } else if mType == downMigration { path = migration.DownPath } else { return InvalidMigrationType } m.logger.Printf("Applying migration: %s", path) sql, err := ioutil.ReadFile(path) if err != nil { m.logger.Printf("Error reading migration: %s", path) return err } transaction, err := m.DB.Begin() if err != nil { m.logger.Printf("Error opening transaction: %v", err) return err } // Certain adapters can not handle multiple sql commands in one file so we need the adapter to split up the command commands := m.dbAdapter.GetMigrationCommands(string(sql)) // Perform the migration. for _, cmd := range commands { result, err := transaction.Exec(cmd) if err != nil { m.logger.Printf("Error executing migration: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } if result != nil { if rowsAffected, err := result.RowsAffected(); err != nil { m.logger.Printf("Error getting rows affected: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } else { m.logger.Printf("Rows affected: %v", rowsAffected) } } } // Log the event. if mType == upMigration { _, err = transaction.Exec( m.dbAdapter.MigrationLogInsertSql(), migration.Id, ) } else { _, err = transaction.Exec( m.dbAdapter.MigrationLogDeleteSql(), migration.Id, ) } if err != nil { m.logger.Printf("Error logging migration: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } // Commit and update the struct status. if err := transaction.Commit(); err != nil { m.logger.Printf("Error commiting transaction: %v", err) return err } if mType == upMigration { migration.Status = Active } else { migration.Status = Inactive } return nil }
go
func (m *Migrator) ApplyMigration(migration *Migration, mType migrationType) error { var path string if mType == upMigration { path = migration.UpPath } else if mType == downMigration { path = migration.DownPath } else { return InvalidMigrationType } m.logger.Printf("Applying migration: %s", path) sql, err := ioutil.ReadFile(path) if err != nil { m.logger.Printf("Error reading migration: %s", path) return err } transaction, err := m.DB.Begin() if err != nil { m.logger.Printf("Error opening transaction: %v", err) return err } // Certain adapters can not handle multiple sql commands in one file so we need the adapter to split up the command commands := m.dbAdapter.GetMigrationCommands(string(sql)) // Perform the migration. for _, cmd := range commands { result, err := transaction.Exec(cmd) if err != nil { m.logger.Printf("Error executing migration: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } if result != nil { if rowsAffected, err := result.RowsAffected(); err != nil { m.logger.Printf("Error getting rows affected: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } else { m.logger.Printf("Rows affected: %v", rowsAffected) } } } // Log the event. if mType == upMigration { _, err = transaction.Exec( m.dbAdapter.MigrationLogInsertSql(), migration.Id, ) } else { _, err = transaction.Exec( m.dbAdapter.MigrationLogDeleteSql(), migration.Id, ) } if err != nil { m.logger.Printf("Error logging migration: %v", err) if rollbackErr := transaction.Rollback(); rollbackErr != nil { m.logger.Printf("Error rolling back transaction: %v", rollbackErr) return rollbackErr } return err } // Commit and update the struct status. if err := transaction.Commit(); err != nil { m.logger.Printf("Error commiting transaction: %v", err) return err } if mType == upMigration { migration.Status = Active } else { migration.Status = Inactive } return nil }
[ "func", "(", "m", "*", "Migrator", ")", "ApplyMigration", "(", "migration", "*", "Migration", ",", "mType", "migrationType", ")", "error", "{", "var", "path", "string", "\n", "if", "mType", "==", "upMigration", "{", "path", "=", "migration", ".", "UpPath", "\n", "}", "else", "if", "mType", "==", "downMigration", "{", "path", "=", "migration", ".", "DownPath", "\n", "}", "else", "{", "return", "InvalidMigrationType", "\n", "}", "\n\n", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "path", ")", "\n\n", "sql", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "path", ")", "\n", "return", "err", "\n", "}", "\n", "transaction", ",", "err", ":=", "m", ".", "DB", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "// Certain adapters can not handle multiple sql commands in one file so we need the adapter to split up the command", "commands", ":=", "m", ".", "dbAdapter", ".", "GetMigrationCommands", "(", "string", "(", "sql", ")", ")", "\n\n", "// Perform the migration.", "for", "_", ",", "cmd", ":=", "range", "commands", "{", "result", ",", "err", ":=", "transaction", ".", "Exec", "(", "cmd", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "if", "rollbackErr", ":=", "transaction", ".", "Rollback", "(", ")", ";", "rollbackErr", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "rollbackErr", ")", "\n", "return", "rollbackErr", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "if", "result", "!=", "nil", "{", "if", "rowsAffected", ",", "err", ":=", "result", ".", "RowsAffected", "(", ")", ";", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "if", "rollbackErr", ":=", "transaction", ".", "Rollback", "(", ")", ";", "rollbackErr", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "rollbackErr", ")", "\n", "return", "rollbackErr", "\n", "}", "\n", "return", "err", "\n", "}", "else", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "rowsAffected", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Log the event.", "if", "mType", "==", "upMigration", "{", "_", ",", "err", "=", "transaction", ".", "Exec", "(", "m", ".", "dbAdapter", ".", "MigrationLogInsertSql", "(", ")", ",", "migration", ".", "Id", ",", ")", "\n", "}", "else", "{", "_", ",", "err", "=", "transaction", ".", "Exec", "(", "m", ".", "dbAdapter", ".", "MigrationLogDeleteSql", "(", ")", ",", "migration", ".", "Id", ",", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "if", "rollbackErr", ":=", "transaction", ".", "Rollback", "(", ")", ";", "rollbackErr", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "rollbackErr", ")", "\n", "return", "rollbackErr", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "// Commit and update the struct status.", "if", "err", ":=", "transaction", ".", "Commit", "(", ")", ";", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "if", "mType", "==", "upMigration", "{", "migration", ".", "Status", "=", "Active", "\n", "}", "else", "{", "migration", ".", "Status", "=", "Inactive", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Applies a single migration.
[ "Applies", "a", "single", "migration", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L213-L297
14,726
DavidHuie/gomigrate
gomigrate.go
Migrate
func (m *Migrator) Migrate() error { for _, migration := range m.Migrations(Inactive) { if err := m.ApplyMigration(migration, upMigration); err != nil { return err } } return nil }
go
func (m *Migrator) Migrate() error { for _, migration := range m.Migrations(Inactive) { if err := m.ApplyMigration(migration, upMigration); err != nil { return err } } return nil }
[ "func", "(", "m", "*", "Migrator", ")", "Migrate", "(", ")", "error", "{", "for", "_", ",", "migration", ":=", "range", "m", ".", "Migrations", "(", "Inactive", ")", "{", "if", "err", ":=", "m", ".", "ApplyMigration", "(", "migration", ",", "upMigration", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Applies all inactive migrations.
[ "Applies", "all", "inactive", "migrations", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L300-L307
14,727
DavidHuie/gomigrate
gomigrate.go
RollbackN
func (m *Migrator) RollbackN(n int) error { migrations := m.Migrations(Active) if len(migrations) == 0 { return nil } last_migration := len(migrations) - 1 - n for i := len(migrations) - 1; i != last_migration; i-- { if err := m.ApplyMigration(migrations[i], downMigration); err != nil { return err } } return nil }
go
func (m *Migrator) RollbackN(n int) error { migrations := m.Migrations(Active) if len(migrations) == 0 { return nil } last_migration := len(migrations) - 1 - n for i := len(migrations) - 1; i != last_migration; i-- { if err := m.ApplyMigration(migrations[i], downMigration); err != nil { return err } } return nil }
[ "func", "(", "m", "*", "Migrator", ")", "RollbackN", "(", "n", "int", ")", "error", "{", "migrations", ":=", "m", ".", "Migrations", "(", "Active", ")", "\n", "if", "len", "(", "migrations", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "last_migration", ":=", "len", "(", "migrations", ")", "-", "1", "-", "n", "\n\n", "for", "i", ":=", "len", "(", "migrations", ")", "-", "1", ";", "i", "!=", "last_migration", ";", "i", "--", "{", "if", "err", ":=", "m", ".", "ApplyMigration", "(", "migrations", "[", "i", "]", ",", "downMigration", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Rolls back N migrations.
[ "Rolls", "back", "N", "migrations", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L315-L330
14,728
DavidHuie/gomigrate
gomigrate.go
RollbackAll
func (m *Migrator) RollbackAll() error { migrations := m.Migrations(Active) return m.RollbackN(len(migrations)) }
go
func (m *Migrator) RollbackAll() error { migrations := m.Migrations(Active) return m.RollbackN(len(migrations)) }
[ "func", "(", "m", "*", "Migrator", ")", "RollbackAll", "(", ")", "error", "{", "migrations", ":=", "m", ".", "Migrations", "(", "Active", ")", "\n", "return", "m", ".", "RollbackN", "(", "len", "(", "migrations", ")", ")", "\n", "}" ]
// Rolls back all migrations.
[ "Rolls", "back", "all", "migrations", "." ]
4004e6142040f5d622e9d2be6e833a4652741571
https://github.com/DavidHuie/gomigrate/blob/4004e6142040f5d622e9d2be6e833a4652741571/gomigrate.go#L333-L336
14,729
crewjam/go-cloudformation
scraper/aws_schema.go
MarshalJSON
func (piType *PropertyItemType) MarshalJSON() ([]byte, error) { var value interface{} if len(piType.Scalar) != 0 { value = piType.Scalar } else { value = piType.MultiValues } return json.Marshal(value) }
go
func (piType *PropertyItemType) MarshalJSON() ([]byte, error) { var value interface{} if len(piType.Scalar) != 0 { value = piType.Scalar } else { value = piType.MultiValues } return json.Marshal(value) }
[ "func", "(", "piType", "*", "PropertyItemType", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "value", "interface", "{", "}", "\n", "if", "len", "(", "piType", ".", "Scalar", ")", "!=", "0", "{", "value", "=", "piType", ".", "Scalar", "\n", "}", "else", "{", "value", "=", "piType", ".", "MultiValues", "\n", "}", "\n", "return", "json", ".", "Marshal", "(", "value", ")", "\n", "}" ]
// MarshalJSON to handle whichever field is set
[ "MarshalJSON", "to", "handle", "whichever", "field", "is", "set" ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/scraper/aws_schema.go#L47-L55
14,730
crewjam/go-cloudformation
scraper/aws_schema.go
UnmarshalJSON
func (piType *PropertyItemType) UnmarshalJSON(data []byte) error { singleString := "" singleErr := json.Unmarshal(data, &singleString) if singleErr == nil { piType.Scalar = singleString return nil } var stringArray []string sliceErr := json.Unmarshal(data, &stringArray) if sliceErr == nil { piType.MultiValues = stringArray return nil } return fmt.Errorf("Failed to unmarshal type: " + sliceErr.Error()) }
go
func (piType *PropertyItemType) UnmarshalJSON(data []byte) error { singleString := "" singleErr := json.Unmarshal(data, &singleString) if singleErr == nil { piType.Scalar = singleString return nil } var stringArray []string sliceErr := json.Unmarshal(data, &stringArray) if sliceErr == nil { piType.MultiValues = stringArray return nil } return fmt.Errorf("Failed to unmarshal type: " + sliceErr.Error()) }
[ "func", "(", "piType", "*", "PropertyItemType", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "singleString", ":=", "\"", "\"", "\n", "singleErr", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "singleString", ")", "\n", "if", "singleErr", "==", "nil", "{", "piType", ".", "Scalar", "=", "singleString", "\n", "return", "nil", "\n", "}", "\n", "var", "stringArray", "[", "]", "string", "\n", "sliceErr", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "stringArray", ")", "\n", "if", "sliceErr", "==", "nil", "{", "piType", ".", "MultiValues", "=", "stringArray", "\n", "return", "nil", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "sliceErr", ".", "Error", "(", ")", ")", "\n", "}" ]
// UnmarshalJSON does the custom unmarshalling
[ "UnmarshalJSON", "does", "the", "custom", "unmarshalling" ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/scraper/aws_schema.go#L58-L72
14,731
crewjam/go-cloudformation
examples/app_old.go
makeTemplateTheOldWay
func makeTemplateTheOldWay() *cf.Template { t := cf.NewTemplate() t.Description = "example production infrastructure" t.Parameters["DnsName"] = &cf.Parameter{ Description: "The top level DNS name for the infrastructure", Type: "String", Default: "preview.example.io", } t.AddResource("ServerLoadBalancer", cf.ElasticLoadBalancingLoadBalancer{ ConnectionDrainingPolicy: &cf.ElasticLoadBalancingConnectionDrainingPolicy{ Enabled: cf.Bool(true), Timeout: cf.Integer(30), }, CrossZone: cf.Bool(true), HealthCheck: &cf.ElasticLoadBalancingHealthCheck{ HealthyThreshold: cf.String("2"), Interval: cf.String("60"), Target: cf.String("HTTP:80/"), Timeout: cf.String("5"), UnhealthyThreshold: cf.String("2"), }, Listeners: &cf.ElasticLoadBalancingListenerList{ cf.ElasticLoadBalancingListener{ InstancePort: cf.String("8000"), InstanceProtocol: cf.String("TCP"), LoadBalancerPort: cf.String("443"), Protocol: cf.String("SSL"), SSLCertificateId: cf.Join("", *cf.String("arn:aws:iam::"), *cf.Ref("AWS::AccountID").String(), *cf.String(":server-certificate/"), *cf.Ref("DnsName").String()).String(), }, }, Policies: &cf.ElasticLoadBalancingPolicyList{ cf.ElasticLoadBalancingPolicy{ PolicyName: cf.String("EnableProxyProtocol"), PolicyType: cf.String("ProxyProtocolPolicyType"), Attributes: []map[string]interface{}{ map[string]interface{}{ "Name": "ProxyProtocol", "Value": "true", }, }, InstancePorts: []int{8000}, }, }, Subnets: cf.StringList( *cf.Ref("VpcSubnetA").String(), *cf.Ref("VpcSubnetB").String(), *cf.Ref("VpcSubnetC").String(), ), SecurityGroups: cf.StringList(*cf.Ref("LoadBalancerSecurityGroup").String()), }) return t }
go
func makeTemplateTheOldWay() *cf.Template { t := cf.NewTemplate() t.Description = "example production infrastructure" t.Parameters["DnsName"] = &cf.Parameter{ Description: "The top level DNS name for the infrastructure", Type: "String", Default: "preview.example.io", } t.AddResource("ServerLoadBalancer", cf.ElasticLoadBalancingLoadBalancer{ ConnectionDrainingPolicy: &cf.ElasticLoadBalancingConnectionDrainingPolicy{ Enabled: cf.Bool(true), Timeout: cf.Integer(30), }, CrossZone: cf.Bool(true), HealthCheck: &cf.ElasticLoadBalancingHealthCheck{ HealthyThreshold: cf.String("2"), Interval: cf.String("60"), Target: cf.String("HTTP:80/"), Timeout: cf.String("5"), UnhealthyThreshold: cf.String("2"), }, Listeners: &cf.ElasticLoadBalancingListenerList{ cf.ElasticLoadBalancingListener{ InstancePort: cf.String("8000"), InstanceProtocol: cf.String("TCP"), LoadBalancerPort: cf.String("443"), Protocol: cf.String("SSL"), SSLCertificateId: cf.Join("", *cf.String("arn:aws:iam::"), *cf.Ref("AWS::AccountID").String(), *cf.String(":server-certificate/"), *cf.Ref("DnsName").String()).String(), }, }, Policies: &cf.ElasticLoadBalancingPolicyList{ cf.ElasticLoadBalancingPolicy{ PolicyName: cf.String("EnableProxyProtocol"), PolicyType: cf.String("ProxyProtocolPolicyType"), Attributes: []map[string]interface{}{ map[string]interface{}{ "Name": "ProxyProtocol", "Value": "true", }, }, InstancePorts: []int{8000}, }, }, Subnets: cf.StringList( *cf.Ref("VpcSubnetA").String(), *cf.Ref("VpcSubnetB").String(), *cf.Ref("VpcSubnetC").String(), ), SecurityGroups: cf.StringList(*cf.Ref("LoadBalancerSecurityGroup").String()), }) return t }
[ "func", "makeTemplateTheOldWay", "(", ")", "*", "cf", ".", "Template", "{", "t", ":=", "cf", ".", "NewTemplate", "(", ")", "\n", "t", ".", "Description", "=", "\"", "\"", "\n", "t", ".", "Parameters", "[", "\"", "\"", "]", "=", "&", "cf", ".", "Parameter", "{", "Description", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "Default", ":", "\"", "\"", ",", "}", "\n\n", "t", ".", "AddResource", "(", "\"", "\"", ",", "cf", ".", "ElasticLoadBalancingLoadBalancer", "{", "ConnectionDrainingPolicy", ":", "&", "cf", ".", "ElasticLoadBalancingConnectionDrainingPolicy", "{", "Enabled", ":", "cf", ".", "Bool", "(", "true", ")", ",", "Timeout", ":", "cf", ".", "Integer", "(", "30", ")", ",", "}", ",", "CrossZone", ":", "cf", ".", "Bool", "(", "true", ")", ",", "HealthCheck", ":", "&", "cf", ".", "ElasticLoadBalancingHealthCheck", "{", "HealthyThreshold", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "Interval", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "Target", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "Timeout", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "UnhealthyThreshold", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "}", ",", "Listeners", ":", "&", "cf", ".", "ElasticLoadBalancingListenerList", "{", "cf", ".", "ElasticLoadBalancingListener", "{", "InstancePort", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "InstanceProtocol", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "LoadBalancerPort", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "Protocol", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "SSLCertificateId", ":", "cf", ".", "Join", "(", "\"", "\"", ",", "*", "cf", ".", "String", "(", "\"", "\"", ")", ",", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ",", "*", "cf", ".", "String", "(", "\"", "\"", ")", ",", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ")", ".", "String", "(", ")", ",", "}", ",", "}", ",", "Policies", ":", "&", "cf", ".", "ElasticLoadBalancingPolicyList", "{", "cf", ".", "ElasticLoadBalancingPolicy", "{", "PolicyName", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "PolicyType", ":", "cf", ".", "String", "(", "\"", "\"", ")", ",", "Attributes", ":", "[", "]", "map", "[", "string", "]", "interface", "{", "}", "{", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", ",", "}", ",", "InstancePorts", ":", "[", "]", "int", "{", "8000", "}", ",", "}", ",", "}", ",", "Subnets", ":", "cf", ".", "StringList", "(", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ",", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ",", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ",", ")", ",", "SecurityGroups", ":", "cf", ".", "StringList", "(", "*", "cf", ".", "Ref", "(", "\"", "\"", ")", ".", "String", "(", ")", ")", ",", "}", ")", "\n\n", "return", "t", "\n", "}" ]
// makeTemplateTheOldWay is an implementation of makeTemplate that uses the // older pre-Stringable syntax. If this file builds, then maybe we haven't broken // backcompat.
[ "makeTemplateTheOldWay", "is", "an", "implementation", "of", "makeTemplate", "that", "uses", "the", "older", "pre", "-", "Stringable", "syntax", ".", "If", "this", "file", "builds", "then", "maybe", "we", "haven", "t", "broken", "backcompat", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/examples/app_old.go#L9-L66
14,732
crewjam/go-cloudformation
func_findinmap.go
FindInMap
func FindInMap(mapName string, topLevelKey Stringable, secondLevelKey Stringable) *StringExpr { return FindInMapFunc{ MapName: mapName, TopLevelKey: *topLevelKey.String(), SecondLevelKey: *secondLevelKey.String(), }.String() }
go
func FindInMap(mapName string, topLevelKey Stringable, secondLevelKey Stringable) *StringExpr { return FindInMapFunc{ MapName: mapName, TopLevelKey: *topLevelKey.String(), SecondLevelKey: *secondLevelKey.String(), }.String() }
[ "func", "FindInMap", "(", "mapName", "string", ",", "topLevelKey", "Stringable", ",", "secondLevelKey", "Stringable", ")", "*", "StringExpr", "{", "return", "FindInMapFunc", "{", "MapName", ":", "mapName", ",", "TopLevelKey", ":", "*", "topLevelKey", ".", "String", "(", ")", ",", "SecondLevelKey", ":", "*", "secondLevelKey", ".", "String", "(", ")", ",", "}", ".", "String", "(", ")", "\n", "}" ]
// FindInMap returns a new instance of FindInMapFunc.
[ "FindInMap", "returns", "a", "new", "instance", "of", "FindInMapFunc", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/func_findinmap.go#L6-L12
14,733
crewjam/go-cloudformation
func.go
unmarshalFunc
func unmarshalFunc(data []byte) (Func, error) { rawDecode := map[string]json.RawMessage{} err := json.Unmarshal(data, &rawDecode) if err != nil { return nil, err } for key := range rawDecode { switch key { case "Ref": f := RefFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Join": f := JoinFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Select": f := SelectFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::GetAtt": f := GetAttFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::FindInMap": f := FindInMapFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Base64": f := Base64Func{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::GetAZs": f := GetAZsFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::If": f := IfFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::ImportValue": f := ImportValueFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } default: return nil, UnknownFunctionError{Name: key} } } return nil, fmt.Errorf("cannot decode function") }
go
func unmarshalFunc(data []byte) (Func, error) { rawDecode := map[string]json.RawMessage{} err := json.Unmarshal(data, &rawDecode) if err != nil { return nil, err } for key := range rawDecode { switch key { case "Ref": f := RefFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Join": f := JoinFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Select": f := SelectFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::GetAtt": f := GetAttFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::FindInMap": f := FindInMapFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::Base64": f := Base64Func{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::GetAZs": f := GetAZsFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::If": f := IfFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } case "Fn::ImportValue": f := ImportValueFunc{} if err := json.Unmarshal(data, &f); err == nil { return f, nil } default: return nil, UnknownFunctionError{Name: key} } } return nil, fmt.Errorf("cannot decode function") }
[ "func", "unmarshalFunc", "(", "data", "[", "]", "byte", ")", "(", "Func", ",", "error", ")", "{", "rawDecode", ":=", "map", "[", "string", "]", "json", ".", "RawMessage", "{", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "rawDecode", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "key", ":=", "range", "rawDecode", "{", "switch", "key", "{", "case", "\"", "\"", ":", "f", ":=", "RefFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "JoinFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "SelectFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "GetAttFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "FindInMapFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "Base64Func", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "GetAZsFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "IfFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "case", "\"", "\"", ":", "f", ":=", "ImportValueFunc", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "f", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "default", ":", "return", "nil", ",", "UnknownFunctionError", "{", "Name", ":", "key", "}", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// unmarshalFunc unmarshals data into a Func, or returns an error // if the function call is invalid.
[ "unmarshalFunc", "unmarshals", "data", "into", "a", "Func", "or", "returns", "an", "error", "if", "the", "function", "call", "is", "invalid", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/func.go#L54-L112
14,734
crewjam/go-cloudformation
func_getatt.go
GetAtt
func GetAtt(resource, name string) *StringExpr { return GetAttFunc{Resource: resource, Name: name}.String() }
go
func GetAtt(resource, name string) *StringExpr { return GetAttFunc{Resource: resource, Name: name}.String() }
[ "func", "GetAtt", "(", "resource", ",", "name", "string", ")", "*", "StringExpr", "{", "return", "GetAttFunc", "{", "Resource", ":", "resource", ",", "Name", ":", "name", "}", ".", "String", "(", ")", "\n", "}" ]
// GetAtt returns a new instance of GetAttFunc.
[ "GetAtt", "returns", "a", "new", "instance", "of", "GetAttFunc", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/func_getatt.go#L6-L8
14,735
crewjam/go-cloudformation
func_join.go
Join
func Join(separator string, items ...Stringable) *StringExpr { return JoinFunc{Separator: separator, Items: *StringList(items...)}.String() }
go
func Join(separator string, items ...Stringable) *StringExpr { return JoinFunc{Separator: separator, Items: *StringList(items...)}.String() }
[ "func", "Join", "(", "separator", "string", ",", "items", "...", "Stringable", ")", "*", "StringExpr", "{", "return", "JoinFunc", "{", "Separator", ":", "separator", ",", "Items", ":", "*", "StringList", "(", "items", "...", ")", "}", ".", "String", "(", ")", "\n", "}" ]
// Join returns a new instance of JoinFunc that joins items with separator.
[ "Join", "returns", "a", "new", "instance", "of", "JoinFunc", "that", "joins", "items", "with", "separator", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/func_join.go#L6-L8
14,736
crewjam/go-cloudformation
deploycfn/watcher.go
NewStackEventWatcher
func NewStackEventWatcher(session client.ConfigProvider, stackName string) (*StackEventWatcher, error) { sw := StackEventWatcher{ Service: cloudformation.New(session), StackName: stackName, seenEvents: map[string]struct{}{}, } err := sw.Service.DescribeStackEventsPages(&cloudformation.DescribeStackEventsInput{ StackName: aws.String(sw.StackName), }, func(p *cloudformation.DescribeStackEventsOutput, _ bool) bool { for _, stackEvent := range p.StackEvents { sw.seenEvents[*stackEvent.EventId] = struct{}{} } return true }) if err != nil { return nil, err } return &sw, nil }
go
func NewStackEventWatcher(session client.ConfigProvider, stackName string) (*StackEventWatcher, error) { sw := StackEventWatcher{ Service: cloudformation.New(session), StackName: stackName, seenEvents: map[string]struct{}{}, } err := sw.Service.DescribeStackEventsPages(&cloudformation.DescribeStackEventsInput{ StackName: aws.String(sw.StackName), }, func(p *cloudformation.DescribeStackEventsOutput, _ bool) bool { for _, stackEvent := range p.StackEvents { sw.seenEvents[*stackEvent.EventId] = struct{}{} } return true }) if err != nil { return nil, err } return &sw, nil }
[ "func", "NewStackEventWatcher", "(", "session", "client", ".", "ConfigProvider", ",", "stackName", "string", ")", "(", "*", "StackEventWatcher", ",", "error", ")", "{", "sw", ":=", "StackEventWatcher", "{", "Service", ":", "cloudformation", ".", "New", "(", "session", ")", ",", "StackName", ":", "stackName", ",", "seenEvents", ":", "map", "[", "string", "]", "struct", "{", "}", "{", "}", ",", "}", "\n\n", "err", ":=", "sw", ".", "Service", ".", "DescribeStackEventsPages", "(", "&", "cloudformation", ".", "DescribeStackEventsInput", "{", "StackName", ":", "aws", ".", "String", "(", "sw", ".", "StackName", ")", ",", "}", ",", "func", "(", "p", "*", "cloudformation", ".", "DescribeStackEventsOutput", ",", "_", "bool", ")", "bool", "{", "for", "_", ",", "stackEvent", ":=", "range", "p", ".", "StackEvents", "{", "sw", ".", "seenEvents", "[", "*", "stackEvent", ".", "EventId", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "return", "true", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "sw", ",", "nil", "\n", "}" ]
// NewStackEventWatcher returns a new StackEventWatcher that emits events for the // specified stack. It scans all the existing events and adds them to seenEvents // so that events the occur prior to the invocation of this function will not be // printed.
[ "NewStackEventWatcher", "returns", "a", "new", "StackEventWatcher", "that", "emits", "events", "for", "the", "specified", "stack", ".", "It", "scans", "all", "the", "existing", "events", "and", "adds", "them", "to", "seenEvents", "so", "that", "events", "the", "occur", "prior", "to", "the", "invocation", "of", "this", "function", "will", "not", "be", "printed", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/deploycfn/watcher.go#L30-L49
14,737
crewjam/go-cloudformation
deploycfn/watcher.go
Watch
func (sw *StackEventWatcher) Watch() error { if sw.seenEvents == nil { sw.seenEvents = map[string]struct{}{} } lastStackStatus := "" for { // print the events for the stack sw.Service.DescribeStackEventsPages(&cloudformation.DescribeStackEventsInput{ StackName: aws.String(sw.StackName), }, func(p *cloudformation.DescribeStackEventsOutput, _ bool) bool { for _, stackEvent := range p.StackEvents { if _, ok := sw.seenEvents[*stackEvent.EventId]; ok { continue } wrapStrPtr := func(s *string) string { if s == nil { return "" } return *s } l := log.WithField("Status", *stackEvent.ResourceStatus) if stackEvent.ResourceType != nil { l = l.WithField("Type", *stackEvent.ResourceType) } if stackEvent.ResourceType != nil { l = l.WithField("Type", *stackEvent.ResourceType) } if stackEvent.PhysicalResourceId != nil { l = l.WithField("PhysicalID", *stackEvent.PhysicalResourceId) } if stackEvent.LogicalResourceId != nil { l = l.WithField("LogicalID", *stackEvent.LogicalResourceId) } if strings.Contains(*stackEvent.ResourceStatus, "FAIL") { l.Error(wrapStrPtr(stackEvent.ResourceStatusReason)) } else { l.Info(wrapStrPtr(stackEvent.ResourceStatusReason)) } sw.seenEvents[*stackEvent.EventId] = struct{}{} } return true }) // monitor the status of the stack describeStacksResponse, err := sw.Service.DescribeStacks(&cloudformation.DescribeStacksInput{ StackName: aws.String(sw.StackName), }) if err != nil { // the stack might not exist yet log.Errorf("DescribeStacks: %s", err) time.Sleep(time.Second) continue } stackStatus := *describeStacksResponse.Stacks[0].StackStatus if stackStatus != lastStackStatus { log.Infof("Stack: %s\n", stackStatus) lastStackStatus = stackStatus } switch stackStatus { case cloudformation.StackStatusCreateComplete: return nil case cloudformation.StackStatusCreateFailed: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusRollbackComplete: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusUpdateRollbackComplete: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusRollbackFailed: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusUpdateComplete: return nil case cloudformation.StackStatusUpdateRollbackFailed: return fmt.Errorf("%s", stackStatus) default: time.Sleep(time.Second * 5) continue } } }
go
func (sw *StackEventWatcher) Watch() error { if sw.seenEvents == nil { sw.seenEvents = map[string]struct{}{} } lastStackStatus := "" for { // print the events for the stack sw.Service.DescribeStackEventsPages(&cloudformation.DescribeStackEventsInput{ StackName: aws.String(sw.StackName), }, func(p *cloudformation.DescribeStackEventsOutput, _ bool) bool { for _, stackEvent := range p.StackEvents { if _, ok := sw.seenEvents[*stackEvent.EventId]; ok { continue } wrapStrPtr := func(s *string) string { if s == nil { return "" } return *s } l := log.WithField("Status", *stackEvent.ResourceStatus) if stackEvent.ResourceType != nil { l = l.WithField("Type", *stackEvent.ResourceType) } if stackEvent.ResourceType != nil { l = l.WithField("Type", *stackEvent.ResourceType) } if stackEvent.PhysicalResourceId != nil { l = l.WithField("PhysicalID", *stackEvent.PhysicalResourceId) } if stackEvent.LogicalResourceId != nil { l = l.WithField("LogicalID", *stackEvent.LogicalResourceId) } if strings.Contains(*stackEvent.ResourceStatus, "FAIL") { l.Error(wrapStrPtr(stackEvent.ResourceStatusReason)) } else { l.Info(wrapStrPtr(stackEvent.ResourceStatusReason)) } sw.seenEvents[*stackEvent.EventId] = struct{}{} } return true }) // monitor the status of the stack describeStacksResponse, err := sw.Service.DescribeStacks(&cloudformation.DescribeStacksInput{ StackName: aws.String(sw.StackName), }) if err != nil { // the stack might not exist yet log.Errorf("DescribeStacks: %s", err) time.Sleep(time.Second) continue } stackStatus := *describeStacksResponse.Stacks[0].StackStatus if stackStatus != lastStackStatus { log.Infof("Stack: %s\n", stackStatus) lastStackStatus = stackStatus } switch stackStatus { case cloudformation.StackStatusCreateComplete: return nil case cloudformation.StackStatusCreateFailed: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusRollbackComplete: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusUpdateRollbackComplete: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusRollbackFailed: return fmt.Errorf("%s", stackStatus) case cloudformation.StackStatusUpdateComplete: return nil case cloudformation.StackStatusUpdateRollbackFailed: return fmt.Errorf("%s", stackStatus) default: time.Sleep(time.Second * 5) continue } } }
[ "func", "(", "sw", "*", "StackEventWatcher", ")", "Watch", "(", ")", "error", "{", "if", "sw", ".", "seenEvents", "==", "nil", "{", "sw", ".", "seenEvents", "=", "map", "[", "string", "]", "struct", "{", "}", "{", "}", "\n", "}", "\n", "lastStackStatus", ":=", "\"", "\"", "\n", "for", "{", "// print the events for the stack", "sw", ".", "Service", ".", "DescribeStackEventsPages", "(", "&", "cloudformation", ".", "DescribeStackEventsInput", "{", "StackName", ":", "aws", ".", "String", "(", "sw", ".", "StackName", ")", ",", "}", ",", "func", "(", "p", "*", "cloudformation", ".", "DescribeStackEventsOutput", ",", "_", "bool", ")", "bool", "{", "for", "_", ",", "stackEvent", ":=", "range", "p", ".", "StackEvents", "{", "if", "_", ",", "ok", ":=", "sw", ".", "seenEvents", "[", "*", "stackEvent", ".", "EventId", "]", ";", "ok", "{", "continue", "\n", "}", "\n", "wrapStrPtr", ":=", "func", "(", "s", "*", "string", ")", "string", "{", "if", "s", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "*", "s", "\n", "}", "\n\n", "l", ":=", "log", ".", "WithField", "(", "\"", "\"", ",", "*", "stackEvent", ".", "ResourceStatus", ")", "\n", "if", "stackEvent", ".", "ResourceType", "!=", "nil", "{", "l", "=", "l", ".", "WithField", "(", "\"", "\"", ",", "*", "stackEvent", ".", "ResourceType", ")", "\n", "}", "\n", "if", "stackEvent", ".", "ResourceType", "!=", "nil", "{", "l", "=", "l", ".", "WithField", "(", "\"", "\"", ",", "*", "stackEvent", ".", "ResourceType", ")", "\n", "}", "\n", "if", "stackEvent", ".", "PhysicalResourceId", "!=", "nil", "{", "l", "=", "l", ".", "WithField", "(", "\"", "\"", ",", "*", "stackEvent", ".", "PhysicalResourceId", ")", "\n", "}", "\n", "if", "stackEvent", ".", "LogicalResourceId", "!=", "nil", "{", "l", "=", "l", ".", "WithField", "(", "\"", "\"", ",", "*", "stackEvent", ".", "LogicalResourceId", ")", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "*", "stackEvent", ".", "ResourceStatus", ",", "\"", "\"", ")", "{", "l", ".", "Error", "(", "wrapStrPtr", "(", "stackEvent", ".", "ResourceStatusReason", ")", ")", "\n", "}", "else", "{", "l", ".", "Info", "(", "wrapStrPtr", "(", "stackEvent", ".", "ResourceStatusReason", ")", ")", "\n", "}", "\n\n", "sw", ".", "seenEvents", "[", "*", "stackEvent", ".", "EventId", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "return", "true", "\n", "}", ")", "\n\n", "// monitor the status of the stack", "describeStacksResponse", ",", "err", ":=", "sw", ".", "Service", ".", "DescribeStacks", "(", "&", "cloudformation", ".", "DescribeStacksInput", "{", "StackName", ":", "aws", ".", "String", "(", "sw", ".", "StackName", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "// the stack might not exist yet", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "time", ".", "Sleep", "(", "time", ".", "Second", ")", "\n", "continue", "\n", "}", "\n\n", "stackStatus", ":=", "*", "describeStacksResponse", ".", "Stacks", "[", "0", "]", ".", "StackStatus", "\n", "if", "stackStatus", "!=", "lastStackStatus", "{", "log", ".", "Infof", "(", "\"", "\\n", "\"", ",", "stackStatus", ")", "\n", "lastStackStatus", "=", "stackStatus", "\n", "}", "\n", "switch", "stackStatus", "{", "case", "cloudformation", ".", "StackStatusCreateComplete", ":", "return", "nil", "\n", "case", "cloudformation", ".", "StackStatusCreateFailed", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stackStatus", ")", "\n", "case", "cloudformation", ".", "StackStatusRollbackComplete", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stackStatus", ")", "\n", "case", "cloudformation", ".", "StackStatusUpdateRollbackComplete", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stackStatus", ")", "\n", "case", "cloudformation", ".", "StackStatusRollbackFailed", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stackStatus", ")", "\n", "case", "cloudformation", ".", "StackStatusUpdateComplete", ":", "return", "nil", "\n", "case", "cloudformation", ".", "StackStatusUpdateRollbackFailed", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stackStatus", ")", "\n", "default", ":", "time", ".", "Sleep", "(", "time", ".", "Second", "*", "5", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}" ]
// Watch monitors the stack for events, reporting each unseen event to the // log channel. Returns when the stack enters a non-transitional state. The // return value is non-nil if the final state is an error state.
[ "Watch", "monitors", "the", "stack", "for", "events", "reporting", "each", "unseen", "event", "to", "the", "log", "channel", ".", "Returns", "when", "the", "stack", "enters", "a", "non", "-", "transitional", "state", ".", "The", "return", "value", "is", "non", "-", "nil", "if", "the", "final", "state", "is", "an", "error", "state", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/deploycfn/watcher.go#L54-L135
14,738
crewjam/go-cloudformation
func_select.go
Select
func Select(selector string, items ...interface{}) *StringExpr { if len(items) == 1 { if itemList, ok := items[0].(StringListable); ok { return SelectFunc{Selector: selector, Items: *itemList.StringList()}.String() } } stringableItems := make([]Stringable, len(items)) for i, item := range items { stringableItems[i] = item.(Stringable) } return SelectFunc{Selector: selector, Items: *StringList(stringableItems...)}.String() }
go
func Select(selector string, items ...interface{}) *StringExpr { if len(items) == 1 { if itemList, ok := items[0].(StringListable); ok { return SelectFunc{Selector: selector, Items: *itemList.StringList()}.String() } } stringableItems := make([]Stringable, len(items)) for i, item := range items { stringableItems[i] = item.(Stringable) } return SelectFunc{Selector: selector, Items: *StringList(stringableItems...)}.String() }
[ "func", "Select", "(", "selector", "string", ",", "items", "...", "interface", "{", "}", ")", "*", "StringExpr", "{", "if", "len", "(", "items", ")", "==", "1", "{", "if", "itemList", ",", "ok", ":=", "items", "[", "0", "]", ".", "(", "StringListable", ")", ";", "ok", "{", "return", "SelectFunc", "{", "Selector", ":", "selector", ",", "Items", ":", "*", "itemList", ".", "StringList", "(", ")", "}", ".", "String", "(", ")", "\n", "}", "\n", "}", "\n", "stringableItems", ":=", "make", "(", "[", "]", "Stringable", ",", "len", "(", "items", ")", ")", "\n", "for", "i", ",", "item", ":=", "range", "items", "{", "stringableItems", "[", "i", "]", "=", "item", ".", "(", "Stringable", ")", "\n", "}", "\n", "return", "SelectFunc", "{", "Selector", ":", "selector", ",", "Items", ":", "*", "StringList", "(", "stringableItems", "...", ")", "}", ".", "String", "(", ")", "\n", "}" ]
// Select returns a new instance of SelectFunc chooses among items via selector. If you
[ "Select", "returns", "a", "new", "instance", "of", "SelectFunc", "chooses", "among", "items", "via", "selector", ".", "If", "you" ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/func_select.go#L11-L22
14,739
crewjam/go-cloudformation
template.go
NewTemplate
func NewTemplate() *Template { return &Template{ AWSTemplateFormatVersion: "2010-09-09", Mappings: map[string]*Mapping{}, Parameters: map[string]*Parameter{}, Resources: map[string]*Resource{}, Outputs: map[string]*Output{}, Conditions: map[string]interface{}{}, } }
go
func NewTemplate() *Template { return &Template{ AWSTemplateFormatVersion: "2010-09-09", Mappings: map[string]*Mapping{}, Parameters: map[string]*Parameter{}, Resources: map[string]*Resource{}, Outputs: map[string]*Output{}, Conditions: map[string]interface{}{}, } }
[ "func", "NewTemplate", "(", ")", "*", "Template", "{", "return", "&", "Template", "{", "AWSTemplateFormatVersion", ":", "\"", "\"", ",", "Mappings", ":", "map", "[", "string", "]", "*", "Mapping", "{", "}", ",", "Parameters", ":", "map", "[", "string", "]", "*", "Parameter", "{", "}", ",", "Resources", ":", "map", "[", "string", "]", "*", "Resource", "{", "}", ",", "Outputs", ":", "map", "[", "string", "]", "*", "Output", "{", "}", ",", "Conditions", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ",", "}", "\n", "}" ]
// NewTemplate returns a new empty Template initialized with some // default values.
[ "NewTemplate", "returns", "a", "new", "empty", "Template", "initialized", "with", "some", "default", "values", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/template.go#L10-L19
14,740
crewjam/go-cloudformation
template.go
AddResource
func (t *Template) AddResource(name string, resource ResourceProperties) *Resource { templateResource := &Resource{Properties: resource} t.Resources[name] = templateResource return templateResource }
go
func (t *Template) AddResource(name string, resource ResourceProperties) *Resource { templateResource := &Resource{Properties: resource} t.Resources[name] = templateResource return templateResource }
[ "func", "(", "t", "*", "Template", ")", "AddResource", "(", "name", "string", ",", "resource", "ResourceProperties", ")", "*", "Resource", "{", "templateResource", ":=", "&", "Resource", "{", "Properties", ":", "resource", "}", "\n", "t", ".", "Resources", "[", "name", "]", "=", "templateResource", "\n", "return", "templateResource", "\n", "}" ]
// AddResource adds the resource to the template as name, displacing // any resource with the same name that already exists.
[ "AddResource", "adds", "the", "resource", "to", "the", "template", "as", "name", "displacing", "any", "resource", "with", "the", "same", "name", "that", "already", "exists", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/template.go#L34-L38
14,741
crewjam/go-cloudformation
iam_policy.go
ToJSON
func (i IAMPolicyDocument) ToJSON() string { buf, err := json.Marshal(i) if err != nil { panic(err) } return string(buf) }
go
func (i IAMPolicyDocument) ToJSON() string { buf, err := json.Marshal(i) if err != nil { panic(err) } return string(buf) }
[ "func", "(", "i", "IAMPolicyDocument", ")", "ToJSON", "(", ")", "string", "{", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "i", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "string", "(", "buf", ")", "\n", "}" ]
// ToJSON returns the JSON representation of the policy document or // panics if the object cannot be marshaled.
[ "ToJSON", "returns", "the", "JSON", "representation", "of", "the", "policy", "document", "or", "panics", "if", "the", "object", "cannot", "be", "marshaled", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/iam_policy.go#L23-L29
14,742
crewjam/go-cloudformation
iam_policy.go
UnmarshalJSON
func (i *IAMPolicyDocument) UnmarshalJSON(data []byte) error { // Handle single statement policy documents var v iamPolicyDocumentSingleStatement err := json.Unmarshal(data, &v) if err == nil { i.Version = v.Version i.Statement = []IAMPolicyStatement{v.Statement} return nil } // Handle multiple statements var v2 iamPolicyDocumentCopy err = json.Unmarshal(data, &v2) if err != nil { return err } i.Version = v2.Version i.Statement = v2.Statement return nil }
go
func (i *IAMPolicyDocument) UnmarshalJSON(data []byte) error { // Handle single statement policy documents var v iamPolicyDocumentSingleStatement err := json.Unmarshal(data, &v) if err == nil { i.Version = v.Version i.Statement = []IAMPolicyStatement{v.Statement} return nil } // Handle multiple statements var v2 iamPolicyDocumentCopy err = json.Unmarshal(data, &v2) if err != nil { return err } i.Version = v2.Version i.Statement = v2.Statement return nil }
[ "func", "(", "i", "*", "IAMPolicyDocument", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "// Handle single statement policy documents", "var", "v", "iamPolicyDocumentSingleStatement", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "v", ")", "\n", "if", "err", "==", "nil", "{", "i", ".", "Version", "=", "v", ".", "Version", "\n", "i", ".", "Statement", "=", "[", "]", "IAMPolicyStatement", "{", "v", ".", "Statement", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Handle multiple statements", "var", "v2", "iamPolicyDocumentCopy", "\n", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "v2", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "i", ".", "Version", "=", "v2", ".", "Version", "\n", "i", ".", "Statement", "=", "v2", ".", "Statement", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON sets the object from the provided JSON representation. This has // been added to handle the special case of a single statement versus an array.
[ "UnmarshalJSON", "sets", "the", "object", "from", "the", "provided", "JSON", "representation", ".", "This", "has", "been", "added", "to", "handle", "the", "special", "case", "of", "a", "single", "statement", "versus", "an", "array", "." ]
38e5b663797c837aa76bea2dd4be52f3563be652
https://github.com/crewjam/go-cloudformation/blob/38e5b663797c837aa76bea2dd4be52f3563be652/iam_policy.go#L33-L54
14,743
mailgun/ttlmap
ttlmap.go
Clock
func Clock(c timetools.TimeProvider) TtlMapOption { return func(m *TtlMap) error { m.clock = c return nil } }
go
func Clock(c timetools.TimeProvider) TtlMapOption { return func(m *TtlMap) error { m.clock = c return nil } }
[ "func", "Clock", "(", "c", "timetools", ".", "TimeProvider", ")", "TtlMapOption", "{", "return", "func", "(", "m", "*", "TtlMap", ")", "error", "{", "m", ".", "clock", "=", "c", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Clock sets the time provider clock, handy for testing
[ "Clock", "sets", "the", "time", "provider", "clock", "handy", "for", "testing" ]
c1c17f74874f2a5ea48bfb06b5459d4ef2689749
https://github.com/mailgun/ttlmap/blob/c1c17f74874f2a5ea48bfb06b5459d4ef2689749/ttlmap.go#L16-L21
14,744
mailgun/ttlmap
ttlmap.go
CallOnExpire
func CallOnExpire(cb Callback) TtlMapOption { return func(m *TtlMap) error { m.onExpire = cb return nil } }
go
func CallOnExpire(cb Callback) TtlMapOption { return func(m *TtlMap) error { m.onExpire = cb return nil } }
[ "func", "CallOnExpire", "(", "cb", "Callback", ")", "TtlMapOption", "{", "return", "func", "(", "m", "*", "TtlMap", ")", "error", "{", "m", ".", "onExpire", "=", "cb", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// CallOnExpire will call this callback on expiration of elements
[ "CallOnExpire", "will", "call", "this", "callback", "on", "expiration", "of", "elements" ]
c1c17f74874f2a5ea48bfb06b5459d4ef2689749
https://github.com/mailgun/ttlmap/blob/c1c17f74874f2a5ea48bfb06b5459d4ef2689749/ttlmap.go#L26-L31
14,745
yosssi/gohtml
writer.go
SetLastElement
func (wr *Writer) SetLastElement(lastElement string) *Writer { wr.lastElement = lastElement return wr }
go
func (wr *Writer) SetLastElement(lastElement string) *Writer { wr.lastElement = lastElement return wr }
[ "func", "(", "wr", "*", "Writer", ")", "SetLastElement", "(", "lastElement", "string", ")", "*", "Writer", "{", "wr", ".", "lastElement", "=", "lastElement", "\n", "return", "wr", "\n", "}" ]
// SetLastElement set the lastElement to the Writer.
[ "SetLastElement", "set", "the", "lastElement", "to", "the", "Writer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/writer.go#L16-L19
14,746
yosssi/gohtml
writer.go
Write
func (wr *Writer) Write(p []byte) (n int, err error) { wr.bf.Write(p) if bytes.HasSuffix(p, []byte(wr.lastElement)) { return wr.writer.Write([]byte(Format(wr.bf.String()) + "\n")) } return 0, nil }
go
func (wr *Writer) Write(p []byte) (n int, err error) { wr.bf.Write(p) if bytes.HasSuffix(p, []byte(wr.lastElement)) { return wr.writer.Write([]byte(Format(wr.bf.String()) + "\n")) } return 0, nil }
[ "func", "(", "wr", "*", "Writer", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "wr", ".", "bf", ".", "Write", "(", "p", ")", "\n", "if", "bytes", ".", "HasSuffix", "(", "p", ",", "[", "]", "byte", "(", "wr", ".", "lastElement", ")", ")", "{", "return", "wr", ".", "writer", ".", "Write", "(", "[", "]", "byte", "(", "Format", "(", "wr", ".", "bf", ".", "String", "(", ")", ")", "+", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "return", "0", ",", "nil", "\n", "}" ]
// Write writes the parameter.
[ "Write", "writes", "the", "parameter", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/writer.go#L22-L28
14,747
yosssi/gohtml
writer.go
NewWriter
func NewWriter(wr io.Writer) *Writer { return &Writer{writer: wr, lastElement: defaultLastElement, bf: &bytes.Buffer{}} }
go
func NewWriter(wr io.Writer) *Writer { return &Writer{writer: wr, lastElement: defaultLastElement, bf: &bytes.Buffer{}} }
[ "func", "NewWriter", "(", "wr", "io", ".", "Writer", ")", "*", "Writer", "{", "return", "&", "Writer", "{", "writer", ":", "wr", ",", "lastElement", ":", "defaultLastElement", ",", "bf", ":", "&", "bytes", ".", "Buffer", "{", "}", "}", "\n", "}" ]
// NewWriter generates a Writer and returns it.
[ "NewWriter", "generates", "a", "Writer", "and", "returns", "it", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/writer.go#L31-L33
14,748
yosssi/gohtml
utils.go
writeLine
func writeLine(bf *bytes.Buffer, indent int, strs ...string) { writeLineFeed(bf) writeIndent(bf, indent) for _, s := range strs { bf.WriteString(s) } }
go
func writeLine(bf *bytes.Buffer, indent int, strs ...string) { writeLineFeed(bf) writeIndent(bf, indent) for _, s := range strs { bf.WriteString(s) } }
[ "func", "writeLine", "(", "bf", "*", "bytes", ".", "Buffer", ",", "indent", "int", ",", "strs", "...", "string", ")", "{", "writeLineFeed", "(", "bf", ")", "\n", "writeIndent", "(", "bf", ",", "indent", ")", "\n", "for", "_", ",", "s", ":=", "range", "strs", "{", "bf", ".", "WriteString", "(", "s", ")", "\n", "}", "\n", "}" ]
// writeLine writes an HTML line to the buffer.
[ "writeLine", "writes", "an", "HTML", "line", "to", "the", "buffer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/utils.go#L9-L15
14,749
yosssi/gohtml
utils.go
writeIndent
func writeIndent(bf *bytes.Buffer, indent int) { bf.WriteString(strings.Repeat(defaultIndentString, indent)) }
go
func writeIndent(bf *bytes.Buffer, indent int) { bf.WriteString(strings.Repeat(defaultIndentString, indent)) }
[ "func", "writeIndent", "(", "bf", "*", "bytes", ".", "Buffer", ",", "indent", "int", ")", "{", "bf", ".", "WriteString", "(", "strings", ".", "Repeat", "(", "defaultIndentString", ",", "indent", ")", ")", "\n", "}" ]
// writeIndent writes indents to the buffer.
[ "writeIndent", "writes", "indents", "to", "the", "buffer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/utils.go#L25-L27
14,750
yosssi/gohtml
tag_element.go
write
func (e *tagElement) write(bf *bytes.Buffer, indent int) { if Condense { l := len(e.children) if l == 0 { writeLine(bf, indent, e.startTagRaw, e.endTagRaw) return } else if l == 1 && e.endTagRaw != "" { if c, ok := e.children[0].(*textElement); ok { writeLine(bf, indent, e.startTagRaw, c.text, e.endTagRaw) return } } } writeLine(bf, indent, e.startTagRaw) for _, c := range e.children { var childIndent int if e.endTagRaw != "" { childIndent = indent + 1 } else { childIndent = indent } c.write(bf, childIndent) } if e.endTagRaw != "" { writeLine(bf, indent, e.endTagRaw) } }
go
func (e *tagElement) write(bf *bytes.Buffer, indent int) { if Condense { l := len(e.children) if l == 0 { writeLine(bf, indent, e.startTagRaw, e.endTagRaw) return } else if l == 1 && e.endTagRaw != "" { if c, ok := e.children[0].(*textElement); ok { writeLine(bf, indent, e.startTagRaw, c.text, e.endTagRaw) return } } } writeLine(bf, indent, e.startTagRaw) for _, c := range e.children { var childIndent int if e.endTagRaw != "" { childIndent = indent + 1 } else { childIndent = indent } c.write(bf, childIndent) } if e.endTagRaw != "" { writeLine(bf, indent, e.endTagRaw) } }
[ "func", "(", "e", "*", "tagElement", ")", "write", "(", "bf", "*", "bytes", ".", "Buffer", ",", "indent", "int", ")", "{", "if", "Condense", "{", "l", ":=", "len", "(", "e", ".", "children", ")", "\n", "if", "l", "==", "0", "{", "writeLine", "(", "bf", ",", "indent", ",", "e", ".", "startTagRaw", ",", "e", ".", "endTagRaw", ")", "\n", "return", "\n", "}", "else", "if", "l", "==", "1", "&&", "e", ".", "endTagRaw", "!=", "\"", "\"", "{", "if", "c", ",", "ok", ":=", "e", ".", "children", "[", "0", "]", ".", "(", "*", "textElement", ")", ";", "ok", "{", "writeLine", "(", "bf", ",", "indent", ",", "e", ".", "startTagRaw", ",", "c", ".", "text", ",", "e", ".", "endTagRaw", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n\n", "writeLine", "(", "bf", ",", "indent", ",", "e", ".", "startTagRaw", ")", "\n", "for", "_", ",", "c", ":=", "range", "e", ".", "children", "{", "var", "childIndent", "int", "\n", "if", "e", ".", "endTagRaw", "!=", "\"", "\"", "{", "childIndent", "=", "indent", "+", "1", "\n", "}", "else", "{", "childIndent", "=", "indent", "\n", "}", "\n", "c", ".", "write", "(", "bf", ",", "childIndent", ")", "\n", "}", "\n", "if", "e", ".", "endTagRaw", "!=", "\"", "\"", "{", "writeLine", "(", "bf", ",", "indent", ",", "e", ".", "endTagRaw", ")", "\n", "}", "\n", "}" ]
// write writes a tag to the buffer.
[ "write", "writes", "a", "tag", "to", "the", "buffer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/tag_element.go#L17-L44
14,751
yosssi/gohtml
tag_element.go
appendChild
func (e *tagElement) appendChild(child element) { e.children = append(e.children, child) }
go
func (e *tagElement) appendChild(child element) { e.children = append(e.children, child) }
[ "func", "(", "e", "*", "tagElement", ")", "appendChild", "(", "child", "element", ")", "{", "e", ".", "children", "=", "append", "(", "e", ".", "children", ",", "child", ")", "\n", "}" ]
// appendChild append an element to the element's children.
[ "appendChild", "append", "an", "element", "to", "the", "element", "s", "children", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/tag_element.go#L47-L49
14,752
yosssi/gohtml
text_element.go
write
func (e *textElement) write(bf *bytes.Buffer, indent int) { lines := strings.Split(strings.Trim(unifyLineFeed(e.text), "\n"), "\n") for _, line := range lines { writeLineFeed(bf) writeIndent(bf, indent) bf.WriteString(line) } }
go
func (e *textElement) write(bf *bytes.Buffer, indent int) { lines := strings.Split(strings.Trim(unifyLineFeed(e.text), "\n"), "\n") for _, line := range lines { writeLineFeed(bf) writeIndent(bf, indent) bf.WriteString(line) } }
[ "func", "(", "e", "*", "textElement", ")", "write", "(", "bf", "*", "bytes", ".", "Buffer", ",", "indent", "int", ")", "{", "lines", ":=", "strings", ".", "Split", "(", "strings", ".", "Trim", "(", "unifyLineFeed", "(", "e", ".", "text", ")", ",", "\"", "\\n", "\"", ")", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "writeLineFeed", "(", "bf", ")", "\n", "writeIndent", "(", "bf", ",", "indent", ")", "\n", "bf", ".", "WriteString", "(", "line", ")", "\n", "}", "\n", "}" ]
// write writes a text to the buffer.
[ "write", "writes", "a", "text", "to", "the", "buffer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/text_element.go#L14-L21
14,753
yosssi/gohtml
parser.go
parse
func parse(r io.Reader) *htmlDocument { htmlDoc := &htmlDocument{} tokenizer := html.NewTokenizer(r) for { if errorToken, _, _ := parseToken(tokenizer, htmlDoc, nil); errorToken { break } } return htmlDoc }
go
func parse(r io.Reader) *htmlDocument { htmlDoc := &htmlDocument{} tokenizer := html.NewTokenizer(r) for { if errorToken, _, _ := parseToken(tokenizer, htmlDoc, nil); errorToken { break } } return htmlDoc }
[ "func", "parse", "(", "r", "io", ".", "Reader", ")", "*", "htmlDocument", "{", "htmlDoc", ":=", "&", "htmlDocument", "{", "}", "\n", "tokenizer", ":=", "html", ".", "NewTokenizer", "(", "r", ")", "\n", "for", "{", "if", "errorToken", ",", "_", ",", "_", ":=", "parseToken", "(", "tokenizer", ",", "htmlDoc", ",", "nil", ")", ";", "errorToken", "{", "break", "\n", "}", "\n", "}", "\n", "return", "htmlDoc", "\n", "}" ]
// parse parses a stirng and converts it into an html.
[ "parse", "parses", "a", "stirng", "and", "converts", "it", "into", "an", "html", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/parser.go#L10-L19
14,754
yosssi/gohtml
parser.go
appendElement
func appendElement(htmlDoc *htmlDocument, parent *tagElement, e element) { if parent != nil { parent.appendChild(e) } else { htmlDoc.append(e) } }
go
func appendElement(htmlDoc *htmlDocument, parent *tagElement, e element) { if parent != nil { parent.appendChild(e) } else { htmlDoc.append(e) } }
[ "func", "appendElement", "(", "htmlDoc", "*", "htmlDocument", ",", "parent", "*", "tagElement", ",", "e", "element", ")", "{", "if", "parent", "!=", "nil", "{", "parent", ".", "appendChild", "(", "e", ")", "\n", "}", "else", "{", "htmlDoc", ".", "append", "(", "e", ")", "\n", "}", "\n", "}" ]
// appendElement appends the element to the htmlDocument or parent tagElement.
[ "appendElement", "appends", "the", "element", "to", "the", "htmlDocument", "or", "parent", "tagElement", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/parser.go#L61-L67
14,755
yosssi/gohtml
parser.go
getTagName
func getTagName(tokenizer *html.Tokenizer) string { tagName, _ := tokenizer.TagName() return string(tagName) }
go
func getTagName(tokenizer *html.Tokenizer) string { tagName, _ := tokenizer.TagName() return string(tagName) }
[ "func", "getTagName", "(", "tokenizer", "*", "html", ".", "Tokenizer", ")", "string", "{", "tagName", ",", "_", ":=", "tokenizer", ".", "TagName", "(", ")", "\n", "return", "string", "(", "tagName", ")", "\n", "}" ]
// getTagName gets a tagName from tokenizer.
[ "getTagName", "gets", "a", "tagName", "from", "tokenizer", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/parser.go#L70-L73
14,756
yosssi/gohtml
parser.go
setEndTagRaw
func setEndTagRaw(tokenizer *html.Tokenizer, parent *tagElement, tagName string) string { if parent != nil && parent.tagName == tagName { parent.endTagRaw = string(tokenizer.Raw()) return "" } return tagName }
go
func setEndTagRaw(tokenizer *html.Tokenizer, parent *tagElement, tagName string) string { if parent != nil && parent.tagName == tagName { parent.endTagRaw = string(tokenizer.Raw()) return "" } return tagName }
[ "func", "setEndTagRaw", "(", "tokenizer", "*", "html", ".", "Tokenizer", ",", "parent", "*", "tagElement", ",", "tagName", "string", ")", "string", "{", "if", "parent", "!=", "nil", "&&", "parent", ".", "tagName", "==", "tagName", "{", "parent", ".", "endTagRaw", "=", "string", "(", "tokenizer", ".", "Raw", "(", ")", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "tagName", "\n", "}" ]
// setEndTagRaw sets an endTagRaw to the parent.
[ "setEndTagRaw", "sets", "an", "endTagRaw", "to", "the", "parent", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/parser.go#L76-L82
14,757
yosssi/gohtml
html_document.go
bytes
func (htmlDoc *htmlDocument) bytes() []byte { bf := &bytes.Buffer{} for _, e := range htmlDoc.elements { e.write(bf, startIndent) } return bf.Bytes() }
go
func (htmlDoc *htmlDocument) bytes() []byte { bf := &bytes.Buffer{} for _, e := range htmlDoc.elements { e.write(bf, startIndent) } return bf.Bytes() }
[ "func", "(", "htmlDoc", "*", "htmlDocument", ")", "bytes", "(", ")", "[", "]", "byte", "{", "bf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "for", "_", ",", "e", ":=", "range", "htmlDoc", ".", "elements", "{", "e", ".", "write", "(", "bf", ",", "startIndent", ")", "\n", "}", "\n", "return", "bf", ".", "Bytes", "(", ")", "\n", "}" ]
// bytes reads from htmlDocument's internal array of elements and returns HTML source code
[ "bytes", "reads", "from", "htmlDocument", "s", "internal", "array", "of", "elements", "and", "returns", "HTML", "source", "code" ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/html_document.go#L16-L22
14,758
yosssi/gohtml
html_document.go
append
func (htmlDoc *htmlDocument) append(e element) { htmlDoc.elements = append(htmlDoc.elements, e) }
go
func (htmlDoc *htmlDocument) append(e element) { htmlDoc.elements = append(htmlDoc.elements, e) }
[ "func", "(", "htmlDoc", "*", "htmlDocument", ")", "append", "(", "e", "element", ")", "{", "htmlDoc", ".", "elements", "=", "append", "(", "htmlDoc", ".", "elements", ",", "e", ")", "\n", "}" ]
// append appends an element to the htmlDocument.
[ "append", "appends", "an", "element", "to", "the", "htmlDocument", "." ]
9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8
https://github.com/yosssi/gohtml/blob/9b7db94d32d9901e7ad2488fddf91f7b9fcc36c8/html_document.go#L25-L27
14,759
posener/wstest
dialer.go
runServer
func (r *recorder) runServer(h http.Handler) { // read from the recorder connection the request sent by the recorder.Dial, // and use the handler to serve this request. req, err := http.ReadRequest(bufio.NewReader(r.server)) if err != nil { return } h.ServeHTTP(r, req) }
go
func (r *recorder) runServer(h http.Handler) { // read from the recorder connection the request sent by the recorder.Dial, // and use the handler to serve this request. req, err := http.ReadRequest(bufio.NewReader(r.server)) if err != nil { return } h.ServeHTTP(r, req) }
[ "func", "(", "r", "*", "recorder", ")", "runServer", "(", "h", "http", ".", "Handler", ")", "{", "// read from the recorder connection the request sent by the recorder.Dial,", "// and use the handler to serve this request.", "req", ",", "err", ":=", "http", ".", "ReadRequest", "(", "bufio", ".", "NewReader", "(", "r", ".", "server", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "h", ".", "ServeHTTP", "(", "r", ",", "req", ")", "\n", "}" ]
// runServer reads the request sent on the connection to the recorder // from the websocket.NewDialer.Dial function, and pass it to the recorder. // once this is done, the communication is done on the wsConn
[ "runServer", "reads", "the", "request", "sent", "on", "the", "connection", "to", "the", "recorder", "from", "the", "websocket", ".", "NewDialer", ".", "Dial", "function", "and", "pass", "it", "to", "the", "recorder", ".", "once", "this", "is", "done", "the", "communication", "is", "done", "on", "the", "wsConn" ]
28272a7ea048139a5b9c30c1cfb591fbd0481686
https://github.com/posener/wstest/blob/28272a7ea048139a5b9c30c1cfb591fbd0481686/dialer.go#L47-L55
14,760
posener/wstest
dialer.go
Hijack
func (r *recorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { // return to the recorder the recorder, which is the recorder side of the connection rw := bufio.NewReadWriter(bufio.NewReader(r.server), bufio.NewWriter(r.server)) return r.server, rw, nil }
go
func (r *recorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { // return to the recorder the recorder, which is the recorder side of the connection rw := bufio.NewReadWriter(bufio.NewReader(r.server), bufio.NewWriter(r.server)) return r.server, rw, nil }
[ "func", "(", "r", "*", "recorder", ")", "Hijack", "(", ")", "(", "net", ".", "Conn", ",", "*", "bufio", ".", "ReadWriter", ",", "error", ")", "{", "// return to the recorder the recorder, which is the recorder side of the connection", "rw", ":=", "bufio", ".", "NewReadWriter", "(", "bufio", ".", "NewReader", "(", "r", ".", "server", ")", ",", "bufio", ".", "NewWriter", "(", "r", ".", "server", ")", ")", "\n", "return", "r", ".", "server", ",", "rw", ",", "nil", "\n", "}" ]
// Hijack the connection
[ "Hijack", "the", "connection" ]
28272a7ea048139a5b9c30c1cfb591fbd0481686
https://github.com/posener/wstest/blob/28272a7ea048139a5b9c30c1cfb591fbd0481686/dialer.go#L58-L62
14,761
posener/wstest
dialer.go
WriteHeader
func (r *recorder) WriteHeader(code int) { resp := http.Response{StatusCode: code, Header: r.Header()} resp.Write(r.server) }
go
func (r *recorder) WriteHeader(code int) { resp := http.Response{StatusCode: code, Header: r.Header()} resp.Write(r.server) }
[ "func", "(", "r", "*", "recorder", ")", "WriteHeader", "(", "code", "int", ")", "{", "resp", ":=", "http", ".", "Response", "{", "StatusCode", ":", "code", ",", "Header", ":", "r", ".", "Header", "(", ")", "}", "\n", "resp", ".", "Write", "(", "r", ".", "server", ")", "\n", "}" ]
// WriteHeader write HTTP header to the client and closes the connection
[ "WriteHeader", "write", "HTTP", "header", "to", "the", "client", "and", "closes", "the", "connection" ]
28272a7ea048139a5b9c30c1cfb591fbd0481686
https://github.com/posener/wstest/blob/28272a7ea048139a5b9c30c1cfb591fbd0481686/dialer.go#L65-L68
14,762
julienschmidt/sse
sse.go
New
func New() *Streamer { s := &Streamer{ event: make(chan []byte, 1), clients: make(map[client]bool), connecting: make(chan client), disconnecting: make(chan client), bufSize: 2, } s.run() return s }
go
func New() *Streamer { s := &Streamer{ event: make(chan []byte, 1), clients: make(map[client]bool), connecting: make(chan client), disconnecting: make(chan client), bufSize: 2, } s.run() return s }
[ "func", "New", "(", ")", "*", "Streamer", "{", "s", ":=", "&", "Streamer", "{", "event", ":", "make", "(", "chan", "[", "]", "byte", ",", "1", ")", ",", "clients", ":", "make", "(", "map", "[", "client", "]", "bool", ")", ",", "connecting", ":", "make", "(", "chan", "client", ")", ",", "disconnecting", ":", "make", "(", "chan", "client", ")", ",", "bufSize", ":", "2", ",", "}", "\n\n", "s", ".", "run", "(", ")", "\n", "return", "s", "\n", "}" ]
// New returns a new initialized SSE Streamer
[ "New", "returns", "a", "new", "initialized", "SSE", "Streamer" ]
dedc8dfa3d5dbf90d2c4d70dfc25e7f8d657b424
https://github.com/julienschmidt/sse/blob/dedc8dfa3d5dbf90d2c4d70dfc25e7f8d657b424/sse.go#L33-L44
14,763
julienschmidt/sse
sse.go
run
func (s *Streamer) run() { go func() { for { select { case cl := <-s.connecting: s.clients[cl] = true case cl := <-s.disconnecting: delete(s.clients, cl) case event := <-s.event: for cl := range s.clients { // TODO: non-blocking broadcast //select { //case cl <- event: // Try to send event to client //default: // fmt.Println("Channel full. Discarding value") //} cl <- event } } } }() }
go
func (s *Streamer) run() { go func() { for { select { case cl := <-s.connecting: s.clients[cl] = true case cl := <-s.disconnecting: delete(s.clients, cl) case event := <-s.event: for cl := range s.clients { // TODO: non-blocking broadcast //select { //case cl <- event: // Try to send event to client //default: // fmt.Println("Channel full. Discarding value") //} cl <- event } } } }() }
[ "func", "(", "s", "*", "Streamer", ")", "run", "(", ")", "{", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "cl", ":=", "<-", "s", ".", "connecting", ":", "s", ".", "clients", "[", "cl", "]", "=", "true", "\n\n", "case", "cl", ":=", "<-", "s", ".", "disconnecting", ":", "delete", "(", "s", ".", "clients", ",", "cl", ")", "\n\n", "case", "event", ":=", "<-", "s", ".", "event", ":", "for", "cl", ":=", "range", "s", ".", "clients", "{", "// TODO: non-blocking broadcast", "//select {", "//case cl <- event: // Try to send event to client", "//default:", "//\tfmt.Println(\"Channel full. Discarding value\")", "//}", "cl", "<-", "event", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// run starts a goroutine to handle client connects and broadcast events.
[ "run", "starts", "a", "goroutine", "to", "handle", "client", "connects", "and", "broadcast", "events", "." ]
dedc8dfa3d5dbf90d2c4d70dfc25e7f8d657b424
https://github.com/julienschmidt/sse/blob/dedc8dfa3d5dbf90d2c4d70dfc25e7f8d657b424/sse.go#L47-L70
14,764
elodina/go-avro
datum_reader.go
NewGenericEnum
func NewGenericEnum(symbols []string) *GenericEnum { symbolsToIndex := make(map[string]int32) for index, symbol := range symbols { symbolsToIndex[symbol] = int32(index) } return &GenericEnum{ Symbols: symbols, symbolsToIndex: symbolsToIndex, } }
go
func NewGenericEnum(symbols []string) *GenericEnum { symbolsToIndex := make(map[string]int32) for index, symbol := range symbols { symbolsToIndex[symbol] = int32(index) } return &GenericEnum{ Symbols: symbols, symbolsToIndex: symbolsToIndex, } }
[ "func", "NewGenericEnum", "(", "symbols", "[", "]", "string", ")", "*", "GenericEnum", "{", "symbolsToIndex", ":=", "make", "(", "map", "[", "string", "]", "int32", ")", "\n", "for", "index", ",", "symbol", ":=", "range", "symbols", "{", "symbolsToIndex", "[", "symbol", "]", "=", "int32", "(", "index", ")", "\n", "}", "\n\n", "return", "&", "GenericEnum", "{", "Symbols", ":", "symbols", ",", "symbolsToIndex", ":", "symbolsToIndex", ",", "}", "\n", "}" ]
// NewGenericEnum returns a new GenericEnum that uses provided enum symbols.
[ "NewGenericEnum", "returns", "a", "new", "GenericEnum", "that", "uses", "provided", "enum", "symbols", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/datum_reader.go#L40-L50
14,765
elodina/go-avro
datum_reader.go
Read
func (reader *GenericDatumReader) Read(v interface{}, dec Decoder) error { rv := reflect.ValueOf(v) if rv.Kind() != reflect.Ptr || rv.IsNil() { return errors.New("Not applicable for non-pointer types or nil") } rv = rv.Elem() if reader.schema == nil { return SchemaNotSet } //read the value value, err := reader.readValue(reader.schema, dec) if err != nil { return err } newValue := reflect.ValueOf(value) // dereference the value if needed if newValue.Kind() == reflect.Ptr { newValue = newValue.Elem() } //set the new value rv.Set(newValue) return nil }
go
func (reader *GenericDatumReader) Read(v interface{}, dec Decoder) error { rv := reflect.ValueOf(v) if rv.Kind() != reflect.Ptr || rv.IsNil() { return errors.New("Not applicable for non-pointer types or nil") } rv = rv.Elem() if reader.schema == nil { return SchemaNotSet } //read the value value, err := reader.readValue(reader.schema, dec) if err != nil { return err } newValue := reflect.ValueOf(value) // dereference the value if needed if newValue.Kind() == reflect.Ptr { newValue = newValue.Elem() } //set the new value rv.Set(newValue) return nil }
[ "func", "(", "reader", "*", "GenericDatumReader", ")", "Read", "(", "v", "interface", "{", "}", ",", "dec", "Decoder", ")", "error", "{", "rv", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "if", "rv", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "rv", ".", "IsNil", "(", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "rv", "=", "rv", ".", "Elem", "(", ")", "\n", "if", "reader", ".", "schema", "==", "nil", "{", "return", "SchemaNotSet", "\n", "}", "\n\n", "//read the value", "value", ",", "err", ":=", "reader", ".", "readValue", "(", "reader", ".", "schema", ",", "dec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "newValue", ":=", "reflect", ".", "ValueOf", "(", "value", ")", "\n", "// dereference the value if needed", "if", "newValue", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "newValue", "=", "newValue", ".", "Elem", "(", ")", "\n", "}", "\n\n", "//set the new value", "rv", ".", "Set", "(", "newValue", ")", "\n\n", "return", "nil", "\n", "}" ]
// Read reads a single entry using this GenericDatumReader. // Accepts a value to fill with data and a Decoder to read from. Given value MUST be of pointer type. // May return an error indicating a read failure.
[ "Read", "reads", "a", "single", "entry", "using", "this", "GenericDatumReader", ".", "Accepts", "a", "value", "to", "fill", "with", "data", "and", "a", "Decoder", "to", "read", "from", ".", "Given", "value", "MUST", "be", "of", "pointer", "type", ".", "May", "return", "an", "error", "indicating", "a", "read", "failure", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/datum_reader.go#L384-L410
14,766
elodina/go-avro
datum_writer.go
Write
func (writer *GenericDatumWriter) Write(obj interface{}, enc Encoder) error { return writer.write(obj, enc, writer.schema) }
go
func (writer *GenericDatumWriter) Write(obj interface{}, enc Encoder) error { return writer.write(obj, enc, writer.schema) }
[ "func", "(", "writer", "*", "GenericDatumWriter", ")", "Write", "(", "obj", "interface", "{", "}", ",", "enc", "Encoder", ")", "error", "{", "return", "writer", ".", "write", "(", "obj", ",", "enc", ",", "writer", ".", "schema", ")", "\n", "}" ]
// Write writes a single entry using this GenericDatumWriter according to provided Schema. // Accepts a value to write and Encoder to write to. // May return an error indicating a write failure.
[ "Write", "writes", "a", "single", "entry", "using", "this", "GenericDatumWriter", "according", "to", "provided", "Schema", ".", "Accepts", "a", "value", "to", "write", "and", "Encoder", "to", "write", "to", ".", "May", "return", "an", "error", "indicating", "a", "write", "failure", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/datum_writer.go#L284-L286
14,767
elodina/go-avro
encoder.go
WriteBoolean
func (be *BinaryEncoder) WriteBoolean(x bool) { if x { _, _ = be.buffer.Write([]byte{0x01}) } else { _, _ = be.buffer.Write([]byte{0x00}) } }
go
func (be *BinaryEncoder) WriteBoolean(x bool) { if x { _, _ = be.buffer.Write([]byte{0x01}) } else { _, _ = be.buffer.Write([]byte{0x00}) } }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteBoolean", "(", "x", "bool", ")", "{", "if", "x", "{", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "[", "]", "byte", "{", "0x01", "}", ")", "\n", "}", "else", "{", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "[", "]", "byte", "{", "0x00", "}", ")", "\n", "}", "\n", "}" ]
// WriteBoolean writes a boolean value.
[ "WriteBoolean", "writes", "a", "boolean", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L72-L78
14,768
elodina/go-avro
encoder.go
WriteInt
func (be *BinaryEncoder) WriteInt(x int32) { _, _ = be.buffer.Write(be.encodeVarint32(x)) }
go
func (be *BinaryEncoder) WriteInt(x int32) { _, _ = be.buffer.Write(be.encodeVarint32(x)) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteInt", "(", "x", "int32", ")", "{", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "be", ".", "encodeVarint32", "(", "x", ")", ")", "\n", "}" ]
// WriteInt writes an int value.
[ "WriteInt", "writes", "an", "int", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L81-L83
14,769
elodina/go-avro
encoder.go
WriteLong
func (be *BinaryEncoder) WriteLong(x int64) { _, _ = be.buffer.Write(be.encodeVarint64(x)) }
go
func (be *BinaryEncoder) WriteLong(x int64) { _, _ = be.buffer.Write(be.encodeVarint64(x)) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteLong", "(", "x", "int64", ")", "{", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "be", ".", "encodeVarint64", "(", "x", ")", ")", "\n", "}" ]
// WriteLong writes a long value.
[ "WriteLong", "writes", "a", "long", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L86-L88
14,770
elodina/go-avro
encoder.go
WriteFloat
func (be *BinaryEncoder) WriteFloat(x float32) { bytes := make([]byte, 4) binary.LittleEndian.PutUint32(bytes, math.Float32bits(x)) _, _ = be.buffer.Write(bytes) }
go
func (be *BinaryEncoder) WriteFloat(x float32) { bytes := make([]byte, 4) binary.LittleEndian.PutUint32(bytes, math.Float32bits(x)) _, _ = be.buffer.Write(bytes) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteFloat", "(", "x", "float32", ")", "{", "bytes", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "bytes", ",", "math", ".", "Float32bits", "(", "x", ")", ")", "\n", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "bytes", ")", "\n", "}" ]
// WriteFloat writes a float value.
[ "WriteFloat", "writes", "a", "float", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L91-L95
14,771
elodina/go-avro
encoder.go
WriteDouble
func (be *BinaryEncoder) WriteDouble(x float64) { bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, math.Float64bits(x)) _, _ = be.buffer.Write(bytes) }
go
func (be *BinaryEncoder) WriteDouble(x float64) { bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, math.Float64bits(x)) _, _ = be.buffer.Write(bytes) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteDouble", "(", "x", "float64", ")", "{", "bytes", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint64", "(", "bytes", ",", "math", ".", "Float64bits", "(", "x", ")", ")", "\n", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "bytes", ")", "\n", "}" ]
// WriteDouble writes a double value.
[ "WriteDouble", "writes", "a", "double", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L98-L102
14,772
elodina/go-avro
encoder.go
WriteRaw
func (be *BinaryEncoder) WriteRaw(x []byte) { _, _ = be.buffer.Write(x) }
go
func (be *BinaryEncoder) WriteRaw(x []byte) { _, _ = be.buffer.Write(x) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteRaw", "(", "x", "[", "]", "byte", ")", "{", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "x", ")", "\n", "}" ]
// WriteRaw writes raw bytes to this Encoder.
[ "WriteRaw", "writes", "raw", "bytes", "to", "this", "Encoder", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L105-L107
14,773
elodina/go-avro
encoder.go
WriteBytes
func (be *BinaryEncoder) WriteBytes(x []byte) { be.WriteLong(int64(len(x))) _, _ = be.buffer.Write(x) }
go
func (be *BinaryEncoder) WriteBytes(x []byte) { be.WriteLong(int64(len(x))) _, _ = be.buffer.Write(x) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteBytes", "(", "x", "[", "]", "byte", ")", "{", "be", ".", "WriteLong", "(", "int64", "(", "len", "(", "x", ")", ")", ")", "\n", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "x", ")", "\n", "}" ]
// WriteBytes writes a bytes value.
[ "WriteBytes", "writes", "a", "bytes", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L110-L113
14,774
elodina/go-avro
encoder.go
WriteString
func (be *BinaryEncoder) WriteString(x string) { be.WriteLong(int64(len(x))) _, _ = be.buffer.Write([]byte(x)) }
go
func (be *BinaryEncoder) WriteString(x string) { be.WriteLong(int64(len(x))) _, _ = be.buffer.Write([]byte(x)) }
[ "func", "(", "be", "*", "BinaryEncoder", ")", "WriteString", "(", "x", "string", ")", "{", "be", ".", "WriteLong", "(", "int64", "(", "len", "(", "x", ")", ")", ")", "\n", "_", ",", "_", "=", "be", ".", "buffer", ".", "Write", "(", "[", "]", "byte", "(", "x", ")", ")", "\n", "}" ]
// WriteString writes a string value.
[ "WriteString", "writes", "a", "string", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/encoder.go#L116-L119
14,775
elodina/go-avro
datum_utils.go
fill
func (rm *reflectInfo) fill(t reflect.Type, indexPrefix []int) { // simple infinite recursion preventer: stop when we are >10 deep. if len(indexPrefix) > 10 { return } fillName := func(tag string, idx []int) { if _, ok := rm.names[tag]; !ok { rm.names[tag] = idx } } // these are anonymous structs to investigate (tail recursion) var toInvestigate [][]int for i := 0; i < t.NumField(); i++ { f := t.Field(i) tag := f.Tag.Get("avro") idx := append(append([]int{}, indexPrefix...), f.Index...) if f.Anonymous && tag == "" && f.Type.Kind() == reflect.Struct { toInvestigate = append(toInvestigate, idx) } else if strings.ToLower(f.Name[:1]) != f.Name[:1] { if tag != "" { fillName(tag, idx) } else { fillName(f.Name, idx) fillName(strings.ToLower(f.Name[:1])+f.Name[1:], idx) } } } for _, idx := range toInvestigate { // recurse into anonymous structs now that we handled the base ones. rm.fill(t.Field(idx[len(idx)-1]).Type, idx) } }
go
func (rm *reflectInfo) fill(t reflect.Type, indexPrefix []int) { // simple infinite recursion preventer: stop when we are >10 deep. if len(indexPrefix) > 10 { return } fillName := func(tag string, idx []int) { if _, ok := rm.names[tag]; !ok { rm.names[tag] = idx } } // these are anonymous structs to investigate (tail recursion) var toInvestigate [][]int for i := 0; i < t.NumField(); i++ { f := t.Field(i) tag := f.Tag.Get("avro") idx := append(append([]int{}, indexPrefix...), f.Index...) if f.Anonymous && tag == "" && f.Type.Kind() == reflect.Struct { toInvestigate = append(toInvestigate, idx) } else if strings.ToLower(f.Name[:1]) != f.Name[:1] { if tag != "" { fillName(tag, idx) } else { fillName(f.Name, idx) fillName(strings.ToLower(f.Name[:1])+f.Name[1:], idx) } } } for _, idx := range toInvestigate { // recurse into anonymous structs now that we handled the base ones. rm.fill(t.Field(idx[len(idx)-1]).Type, idx) } }
[ "func", "(", "rm", "*", "reflectInfo", ")", "fill", "(", "t", "reflect", ".", "Type", ",", "indexPrefix", "[", "]", "int", ")", "{", "// simple infinite recursion preventer: stop when we are >10 deep.", "if", "len", "(", "indexPrefix", ")", ">", "10", "{", "return", "\n", "}", "\n\n", "fillName", ":=", "func", "(", "tag", "string", ",", "idx", "[", "]", "int", ")", "{", "if", "_", ",", "ok", ":=", "rm", ".", "names", "[", "tag", "]", ";", "!", "ok", "{", "rm", ".", "names", "[", "tag", "]", "=", "idx", "\n", "}", "\n", "}", "\n", "// these are anonymous structs to investigate (tail recursion)", "var", "toInvestigate", "[", "]", "[", "]", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "t", ".", "NumField", "(", ")", ";", "i", "++", "{", "f", ":=", "t", ".", "Field", "(", "i", ")", "\n", "tag", ":=", "f", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", "\n", "idx", ":=", "append", "(", "append", "(", "[", "]", "int", "{", "}", ",", "indexPrefix", "...", ")", ",", "f", ".", "Index", "...", ")", "\n\n", "if", "f", ".", "Anonymous", "&&", "tag", "==", "\"", "\"", "&&", "f", ".", "Type", ".", "Kind", "(", ")", "==", "reflect", ".", "Struct", "{", "toInvestigate", "=", "append", "(", "toInvestigate", ",", "idx", ")", "\n", "}", "else", "if", "strings", ".", "ToLower", "(", "f", ".", "Name", "[", ":", "1", "]", ")", "!=", "f", ".", "Name", "[", ":", "1", "]", "{", "if", "tag", "!=", "\"", "\"", "{", "fillName", "(", "tag", ",", "idx", ")", "\n", "}", "else", "{", "fillName", "(", "f", ".", "Name", ",", "idx", ")", "\n", "fillName", "(", "strings", ".", "ToLower", "(", "f", ".", "Name", "[", ":", "1", "]", ")", "+", "f", ".", "Name", "[", "1", ":", "]", ",", "idx", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "_", ",", "idx", ":=", "range", "toInvestigate", "{", "// recurse into anonymous structs now that we handled the base ones.", "rm", ".", "fill", "(", "t", ".", "Field", "(", "idx", "[", "len", "(", "idx", ")", "-", "1", "]", ")", ".", "Type", ",", "idx", ")", "\n", "}", "\n", "}" ]
// fill the given reflect info with the field names mapped. // // fill will recurse into anonymous structs incrementing the index prefix // so that untagged anonymous structs can be used as the source of truth.
[ "fill", "the", "given", "reflect", "info", "with", "the", "field", "names", "mapped", ".", "fill", "will", "recurse", "into", "anonymous", "structs", "incrementing", "the", "index", "prefix", "so", "that", "untagged", "anonymous", "structs", "can", "be", "used", "as", "the", "source", "of", "truth", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/datum_utils.go#L68-L101
14,776
elodina/go-avro
codegen.go
NewCodeGenerator
func NewCodeGenerator(schemas []string) *CodeGenerator { return &CodeGenerator{ rawSchemas: schemas, structs: make(map[string]*bytes.Buffer), codeSnippets: make([]*bytes.Buffer, 0), schemaDefinitions: &bytes.Buffer{}, } }
go
func NewCodeGenerator(schemas []string) *CodeGenerator { return &CodeGenerator{ rawSchemas: schemas, structs: make(map[string]*bytes.Buffer), codeSnippets: make([]*bytes.Buffer, 0), schemaDefinitions: &bytes.Buffer{}, } }
[ "func", "NewCodeGenerator", "(", "schemas", "[", "]", "string", ")", "*", "CodeGenerator", "{", "return", "&", "CodeGenerator", "{", "rawSchemas", ":", "schemas", ",", "structs", ":", "make", "(", "map", "[", "string", "]", "*", "bytes", ".", "Buffer", ")", ",", "codeSnippets", ":", "make", "(", "[", "]", "*", "bytes", ".", "Buffer", ",", "0", ")", ",", "schemaDefinitions", ":", "&", "bytes", ".", "Buffer", "{", "}", ",", "}", "\n", "}" ]
// NewCodeGenerator creates a new CodeGenerator for given Avro schemas.
[ "NewCodeGenerator", "creates", "a", "new", "CodeGenerator", "for", "given", "Avro", "schemas", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/codegen.go#L36-L43
14,777
elodina/go-avro
decoder.go
ReadInt
func (bd *BinaryDecoder) ReadInt() (int32, error) { if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return 0, EOF } var value uint32 var b uint8 var offset int bufLen := int64(len(bd.buf)) for { if offset == maxIntBufSize { return 0, IntOverflow } if bd.pos >= bufLen { return 0, InvalidInt } b = bd.buf[bd.pos] value |= uint32(b&0x7F) << uint(7*offset) bd.pos++ offset++ if b&0x80 == 0 { break } } return int32((value >> 1) ^ -(value & 1)), nil }
go
func (bd *BinaryDecoder) ReadInt() (int32, error) { if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return 0, EOF } var value uint32 var b uint8 var offset int bufLen := int64(len(bd.buf)) for { if offset == maxIntBufSize { return 0, IntOverflow } if bd.pos >= bufLen { return 0, InvalidInt } b = bd.buf[bd.pos] value |= uint32(b&0x7F) << uint(7*offset) bd.pos++ offset++ if b&0x80 == 0 { break } } return int32((value >> 1) ^ -(value & 1)), nil }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadInt", "(", ")", "(", "int32", ",", "error", ")", "{", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "EOF", "\n", "}", "\n", "var", "value", "uint32", "\n", "var", "b", "uint8", "\n", "var", "offset", "int", "\n", "bufLen", ":=", "int64", "(", "len", "(", "bd", ".", "buf", ")", ")", "\n\n", "for", "{", "if", "offset", "==", "maxIntBufSize", "{", "return", "0", ",", "IntOverflow", "\n", "}", "\n\n", "if", "bd", ".", "pos", ">=", "bufLen", "{", "return", "0", ",", "InvalidInt", "\n", "}", "\n\n", "b", "=", "bd", ".", "buf", "[", "bd", ".", "pos", "]", "\n", "value", "|=", "uint32", "(", "b", "&", "0x7F", ")", "<<", "uint", "(", "7", "*", "offset", ")", "\n", "bd", ".", "pos", "++", "\n", "offset", "++", "\n", "if", "b", "&", "0x80", "==", "0", "{", "break", "\n", "}", "\n", "}", "\n", "return", "int32", "(", "(", "value", ">>", "1", ")", "^", "-", "(", "value", "&", "1", ")", ")", ",", "nil", "\n", "}" ]
// ReadInt reads an int value. Returns a decoded value and an error if it occurs.
[ "ReadInt", "reads", "an", "int", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L110-L137
14,778
elodina/go-avro
decoder.go
ReadLong
func (bd *BinaryDecoder) ReadLong() (int64, error) { var value uint64 var b uint8 var offset int bufLen := int64(len(bd.buf)) for { if offset == maxLongBufSize { return 0, LongOverflow } if bd.pos >= bufLen { return 0, InvalidLong } b = bd.buf[bd.pos] value |= uint64(b&0x7F) << uint(7*offset) bd.pos++ offset++ if b&0x80 == 0 { break } } return int64((value >> 1) ^ -(value & 1)), nil }
go
func (bd *BinaryDecoder) ReadLong() (int64, error) { var value uint64 var b uint8 var offset int bufLen := int64(len(bd.buf)) for { if offset == maxLongBufSize { return 0, LongOverflow } if bd.pos >= bufLen { return 0, InvalidLong } b = bd.buf[bd.pos] value |= uint64(b&0x7F) << uint(7*offset) bd.pos++ offset++ if b&0x80 == 0 { break } } return int64((value >> 1) ^ -(value & 1)), nil }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadLong", "(", ")", "(", "int64", ",", "error", ")", "{", "var", "value", "uint64", "\n", "var", "b", "uint8", "\n", "var", "offset", "int", "\n", "bufLen", ":=", "int64", "(", "len", "(", "bd", ".", "buf", ")", ")", "\n\n", "for", "{", "if", "offset", "==", "maxLongBufSize", "{", "return", "0", ",", "LongOverflow", "\n", "}", "\n\n", "if", "bd", ".", "pos", ">=", "bufLen", "{", "return", "0", ",", "InvalidLong", "\n", "}", "\n\n", "b", "=", "bd", ".", "buf", "[", "bd", ".", "pos", "]", "\n", "value", "|=", "uint64", "(", "b", "&", "0x7F", ")", "<<", "uint", "(", "7", "*", "offset", ")", "\n", "bd", ".", "pos", "++", "\n", "offset", "++", "\n\n", "if", "b", "&", "0x80", "==", "0", "{", "break", "\n", "}", "\n", "}", "\n", "return", "int64", "(", "(", "value", ">>", "1", ")", "^", "-", "(", "value", "&", "1", ")", ")", ",", "nil", "\n", "}" ]
// ReadLong reads a long value. Returns a decoded value and an error if it occurs.
[ "ReadLong", "reads", "a", "long", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L140-L165
14,779
elodina/go-avro
decoder.go
ReadString
func (bd *BinaryDecoder) ReadString() (string, error) { if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return "", err } length, err := bd.ReadLong() if err != nil || length < 0 { return "", InvalidStringLength } if err := checkEOF(bd.buf, bd.pos, int(length)); err != nil { return "", err } value := string(bd.buf[bd.pos : bd.pos+length]) bd.pos += length return value, nil }
go
func (bd *BinaryDecoder) ReadString() (string, error) { if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return "", err } length, err := bd.ReadLong() if err != nil || length < 0 { return "", InvalidStringLength } if err := checkEOF(bd.buf, bd.pos, int(length)); err != nil { return "", err } value := string(bd.buf[bd.pos : bd.pos+length]) bd.pos += length return value, nil }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadString", "(", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "length", ",", "err", ":=", "bd", ".", "ReadLong", "(", ")", "\n", "if", "err", "!=", "nil", "||", "length", "<", "0", "{", "return", "\"", "\"", ",", "InvalidStringLength", "\n", "}", "\n", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "int", "(", "length", ")", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "value", ":=", "string", "(", "bd", ".", "buf", "[", "bd", ".", "pos", ":", "bd", ".", "pos", "+", "length", "]", ")", "\n", "bd", ".", "pos", "+=", "length", "\n", "return", "value", ",", "nil", "\n", "}" ]
// ReadString reads a string value. Returns a decoded value and an error if it occurs.
[ "ReadString", "reads", "a", "string", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L168-L182
14,780
elodina/go-avro
decoder.go
ReadBoolean
func (bd *BinaryDecoder) ReadBoolean() (bool, error) { b := bd.buf[bd.pos] & 0xFF bd.pos++ var err error if b != 0 && b != 1 { err = InvalidBool } return b == 1, err }
go
func (bd *BinaryDecoder) ReadBoolean() (bool, error) { b := bd.buf[bd.pos] & 0xFF bd.pos++ var err error if b != 0 && b != 1 { err = InvalidBool } return b == 1, err }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadBoolean", "(", ")", "(", "bool", ",", "error", ")", "{", "b", ":=", "bd", ".", "buf", "[", "bd", ".", "pos", "]", "&", "0xFF", "\n", "bd", ".", "pos", "++", "\n", "var", "err", "error", "\n", "if", "b", "!=", "0", "&&", "b", "!=", "1", "{", "err", "=", "InvalidBool", "\n", "}", "\n", "return", "b", "==", "1", ",", "err", "\n", "}" ]
// ReadBoolean reads a boolean value. Returns a decoded value and an error if it occurs.
[ "ReadBoolean", "reads", "a", "boolean", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L185-L193
14,781
elodina/go-avro
decoder.go
ReadBytes
func (bd *BinaryDecoder) ReadBytes() ([]byte, error) { //TODO make something with these if's!! if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return nil, EOF } length, err := bd.ReadLong() if err != nil { return nil, err } if length < 0 { return nil, NegativeBytesLength } if err = checkEOF(bd.buf, bd.pos, int(length)); err != nil { return nil, EOF } bytes := make([]byte, length) copy(bytes[:], bd.buf[bd.pos:bd.pos+length]) bd.pos += length return bytes, err }
go
func (bd *BinaryDecoder) ReadBytes() ([]byte, error) { //TODO make something with these if's!! if err := checkEOF(bd.buf, bd.pos, 1); err != nil { return nil, EOF } length, err := bd.ReadLong() if err != nil { return nil, err } if length < 0 { return nil, NegativeBytesLength } if err = checkEOF(bd.buf, bd.pos, int(length)); err != nil { return nil, EOF } bytes := make([]byte, length) copy(bytes[:], bd.buf[bd.pos:bd.pos+length]) bd.pos += length return bytes, err }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadBytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "//TODO make something with these if's!!", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "EOF", "\n", "}", "\n", "length", ",", "err", ":=", "bd", ".", "ReadLong", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "length", "<", "0", "{", "return", "nil", ",", "NegativeBytesLength", "\n", "}", "\n", "if", "err", "=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "int", "(", "length", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "EOF", "\n", "}", "\n\n", "bytes", ":=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "copy", "(", "bytes", "[", ":", "]", ",", "bd", ".", "buf", "[", "bd", ".", "pos", ":", "bd", ".", "pos", "+", "length", "]", ")", "\n", "bd", ".", "pos", "+=", "length", "\n", "return", "bytes", ",", "err", "\n", "}" ]
// ReadBytes reads a bytes value. Returns a decoded value and an error if it occurs.
[ "ReadBytes", "reads", "a", "bytes", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L196-L216
14,782
elodina/go-avro
decoder.go
ReadFloat
func (bd *BinaryDecoder) ReadFloat() (float32, error) { var float float32 if err := checkEOF(bd.buf, bd.pos, 4); err != nil { return float, err } bits := binary.LittleEndian.Uint32(bd.buf[bd.pos : bd.pos+4]) float = math.Float32frombits(bits) bd.pos += 4 return float, nil }
go
func (bd *BinaryDecoder) ReadFloat() (float32, error) { var float float32 if err := checkEOF(bd.buf, bd.pos, 4); err != nil { return float, err } bits := binary.LittleEndian.Uint32(bd.buf[bd.pos : bd.pos+4]) float = math.Float32frombits(bits) bd.pos += 4 return float, nil }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadFloat", "(", ")", "(", "float32", ",", "error", ")", "{", "var", "float", "float32", "\n", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "4", ")", ";", "err", "!=", "nil", "{", "return", "float", ",", "err", "\n", "}", "\n", "bits", ":=", "binary", ".", "LittleEndian", ".", "Uint32", "(", "bd", ".", "buf", "[", "bd", ".", "pos", ":", "bd", ".", "pos", "+", "4", "]", ")", "\n", "float", "=", "math", ".", "Float32frombits", "(", "bits", ")", "\n", "bd", ".", "pos", "+=", "4", "\n", "return", "float", ",", "nil", "\n", "}" ]
// ReadFloat reads a float value. Returns a decoded value and an error if it occurs.
[ "ReadFloat", "reads", "a", "float", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L219-L228
14,783
elodina/go-avro
decoder.go
ReadDouble
func (bd *BinaryDecoder) ReadDouble() (float64, error) { var double float64 if err := checkEOF(bd.buf, bd.pos, 8); err != nil { return double, err } bits := binary.LittleEndian.Uint64(bd.buf[bd.pos : bd.pos+8]) double = math.Float64frombits(bits) bd.pos += 8 return double, nil }
go
func (bd *BinaryDecoder) ReadDouble() (float64, error) { var double float64 if err := checkEOF(bd.buf, bd.pos, 8); err != nil { return double, err } bits := binary.LittleEndian.Uint64(bd.buf[bd.pos : bd.pos+8]) double = math.Float64frombits(bits) bd.pos += 8 return double, nil }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadDouble", "(", ")", "(", "float64", ",", "error", ")", "{", "var", "double", "float64", "\n", "if", "err", ":=", "checkEOF", "(", "bd", ".", "buf", ",", "bd", ".", "pos", ",", "8", ")", ";", "err", "!=", "nil", "{", "return", "double", ",", "err", "\n", "}", "\n", "bits", ":=", "binary", ".", "LittleEndian", ".", "Uint64", "(", "bd", ".", "buf", "[", "bd", ".", "pos", ":", "bd", ".", "pos", "+", "8", "]", ")", "\n", "double", "=", "math", ".", "Float64frombits", "(", "bits", ")", "\n", "bd", ".", "pos", "+=", "8", "\n", "return", "double", ",", "nil", "\n", "}" ]
// ReadDouble reads a double value. Returns a decoded value and an error if it occurs.
[ "ReadDouble", "reads", "a", "double", "value", ".", "Returns", "a", "decoded", "value", "and", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L231-L240
14,784
elodina/go-avro
decoder.go
ReadFixed
func (bd *BinaryDecoder) ReadFixed(bytes []byte) error { return bd.readBytes(bytes, 0, len(bytes)) }
go
func (bd *BinaryDecoder) ReadFixed(bytes []byte) error { return bd.readBytes(bytes, 0, len(bytes)) }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadFixed", "(", "bytes", "[", "]", "byte", ")", "error", "{", "return", "bd", ".", "readBytes", "(", "bytes", ",", "0", ",", "len", "(", "bytes", ")", ")", "\n", "}" ]
// ReadFixed reads fixed sized binary object into the provided buffer. // Returns an error if it occurs.
[ "ReadFixed", "reads", "fixed", "sized", "binary", "object", "into", "the", "provided", "buffer", ".", "Returns", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L275-L277
14,785
elodina/go-avro
decoder.go
ReadFixedWithBounds
func (bd *BinaryDecoder) ReadFixedWithBounds(bytes []byte, start int, length int) error { return bd.readBytes(bytes, start, length) }
go
func (bd *BinaryDecoder) ReadFixedWithBounds(bytes []byte, start int, length int) error { return bd.readBytes(bytes, start, length) }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "ReadFixedWithBounds", "(", "bytes", "[", "]", "byte", ",", "start", "int", ",", "length", "int", ")", "error", "{", "return", "bd", ".", "readBytes", "(", "bytes", ",", "start", ",", "length", ")", "\n", "}" ]
// ReadFixedWithBounds reads fixed sized binary object into the provided buffer. // The second parameter is the position where the data needs to be written, the third is the size of binary object. // Returns an error if it occurs.
[ "ReadFixedWithBounds", "reads", "fixed", "sized", "binary", "object", "into", "the", "provided", "buffer", ".", "The", "second", "parameter", "is", "the", "position", "where", "the", "data", "needs", "to", "be", "written", "the", "third", "is", "the", "size", "of", "binary", "object", ".", "Returns", "an", "error", "if", "it", "occurs", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L282-L284
14,786
elodina/go-avro
decoder.go
SetBlock
func (bd *BinaryDecoder) SetBlock(block *DataBlock) { bd.buf = block.Data bd.Seek(0) }
go
func (bd *BinaryDecoder) SetBlock(block *DataBlock) { bd.buf = block.Data bd.Seek(0) }
[ "func", "(", "bd", "*", "BinaryDecoder", ")", "SetBlock", "(", "block", "*", "DataBlock", ")", "{", "bd", ".", "buf", "=", "block", ".", "Data", "\n", "bd", ".", "Seek", "(", "0", ")", "\n", "}" ]
// SetBlock is used for Avro Object Container Files where the data is split in blocks and sets a data block // for this decoder and sets the position to the start of this block.
[ "SetBlock", "is", "used", "for", "Avro", "Object", "Container", "Files", "where", "the", "data", "is", "split", "in", "blocks", "and", "sets", "a", "data", "block", "for", "this", "decoder", "and", "sets", "the", "position", "to", "the", "start", "of", "this", "block", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/decoder.go#L288-L291
14,787
elodina/go-avro
generic_record.go
NewGenericRecord
func NewGenericRecord(schema Schema) *GenericRecord { return &GenericRecord{ fields: make(map[string]interface{}), schema: schema, } }
go
func NewGenericRecord(schema Schema) *GenericRecord { return &GenericRecord{ fields: make(map[string]interface{}), schema: schema, } }
[ "func", "NewGenericRecord", "(", "schema", "Schema", ")", "*", "GenericRecord", "{", "return", "&", "GenericRecord", "{", "fields", ":", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ",", "schema", ":", "schema", ",", "}", "\n", "}" ]
// NewGenericRecord creates a new GenericRecord.
[ "NewGenericRecord", "creates", "a", "new", "GenericRecord", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/generic_record.go#L34-L39
14,788
elodina/go-avro
generic_record.go
Set
func (gr *GenericRecord) Set(name string, value interface{}) { gr.fields[name] = value }
go
func (gr *GenericRecord) Set(name string, value interface{}) { gr.fields[name] = value }
[ "func", "(", "gr", "*", "GenericRecord", ")", "Set", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "gr", ".", "fields", "[", "name", "]", "=", "value", "\n", "}" ]
// Set sets a value for a given name.
[ "Set", "sets", "a", "value", "for", "a", "given", "name", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/generic_record.go#L47-L49
14,789
elodina/go-avro
generic_record.go
String
func (gr *GenericRecord) String() string { m := gr.Map() buf, err := json.Marshal(m) if err != nil { panic(err) } return string(buf) }
go
func (gr *GenericRecord) String() string { m := gr.Map() buf, err := json.Marshal(m) if err != nil { panic(err) } return string(buf) }
[ "func", "(", "gr", "*", "GenericRecord", ")", "String", "(", ")", "string", "{", "m", ":=", "gr", ".", "Map", "(", ")", "\n", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "string", "(", "buf", ")", "\n", "}" ]
// String returns a JSON representation of this GenericRecord.
[ "String", "returns", "a", "JSON", "representation", "of", "this", "GenericRecord", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/generic_record.go#L57-L64
14,790
elodina/go-avro
generic_record.go
Map
func (gr *GenericRecord) Map() map[string]interface{} { m := make(map[string]interface{}) for k, v := range gr.fields { if r, ok := v.(*GenericRecord); ok { v = r.Map() } if a, ok := v.([]interface{}); ok { slice := make([]interface{}, len(a)) for i, elem := range a { if rec, ok := elem.(*GenericRecord); ok { elem = rec.Map() } slice[i] = elem } v = slice } m[k] = v } return m }
go
func (gr *GenericRecord) Map() map[string]interface{} { m := make(map[string]interface{}) for k, v := range gr.fields { if r, ok := v.(*GenericRecord); ok { v = r.Map() } if a, ok := v.([]interface{}); ok { slice := make([]interface{}, len(a)) for i, elem := range a { if rec, ok := elem.(*GenericRecord); ok { elem = rec.Map() } slice[i] = elem } v = slice } m[k] = v } return m }
[ "func", "(", "gr", "*", "GenericRecord", ")", "Map", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "gr", ".", "fields", "{", "if", "r", ",", "ok", ":=", "v", ".", "(", "*", "GenericRecord", ")", ";", "ok", "{", "v", "=", "r", ".", "Map", "(", ")", "\n", "}", "\n", "if", "a", ",", "ok", ":=", "v", ".", "(", "[", "]", "interface", "{", "}", ")", ";", "ok", "{", "slice", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "a", ")", ")", "\n", "for", "i", ",", "elem", ":=", "range", "a", "{", "if", "rec", ",", "ok", ":=", "elem", ".", "(", "*", "GenericRecord", ")", ";", "ok", "{", "elem", "=", "rec", ".", "Map", "(", ")", "\n", "}", "\n", "slice", "[", "i", "]", "=", "elem", "\n", "}", "\n", "v", "=", "slice", "\n", "}", "\n", "m", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "m", "\n", "}" ]
// Map returns a map representation of this GenericRecord.
[ "Map", "returns", "a", "map", "representation", "of", "this", "GenericRecord", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/generic_record.go#L67-L86
14,791
elodina/go-avro
schema.go
MarshalJSON
func (s *RecursiveSchema) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`"%s"`, s.Actual.GetName())), nil }
go
func (s *RecursiveSchema) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`"%s"`, s.Actual.GetName())), nil }
[ "func", "(", "s", "*", "RecursiveSchema", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "`\"%s\"`", ",", "s", ".", "Actual", ".", "GetName", "(", ")", ")", ")", ",", "nil", "\n", "}" ]
// MarshalJSON serializes the given schema as JSON. Never returns an error.
[ "MarshalJSON", "serializes", "the", "given", "schema", "as", "JSON", ".", "Never", "returns", "an", "error", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L536-L538
14,792
elodina/go-avro
schema.go
Prop
func (this *SchemaField) Prop(key string) (interface{}, bool) { if this.Properties != nil { if prop, ok := this.Properties[key]; ok { return prop, true } } return nil, false }
go
func (this *SchemaField) Prop(key string) (interface{}, bool) { if this.Properties != nil { if prop, ok := this.Properties[key]; ok { return prop, true } } return nil, false }
[ "func", "(", "this", "*", "SchemaField", ")", "Prop", "(", "key", "string", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "this", ".", "Properties", "!=", "nil", "{", "if", "prop", ",", "ok", ":=", "this", ".", "Properties", "[", "key", "]", ";", "ok", "{", "return", "prop", ",", "true", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// Gets a custom non-reserved property from this schemafield and a bool representing if it exists.
[ "Gets", "a", "custom", "non", "-", "reserved", "property", "from", "this", "schemafield", "and", "a", "bool", "representing", "if", "it", "exists", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L550-L557
14,793
elodina/go-avro
schema.go
String
func (s *SchemaField) String() string { return fmt.Sprintf("[SchemaField: Name: %s, Doc: %s, Default: %v, Type: %s]", s.Name, s.Doc, s.Default, s.Type) }
go
func (s *SchemaField) String() string { return fmt.Sprintf("[SchemaField: Name: %s, Doc: %s, Default: %v, Type: %s]", s.Name, s.Doc, s.Default, s.Type) }
[ "func", "(", "s", "*", "SchemaField", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Name", ",", "s", ".", "Doc", ",", "s", ".", "Default", ",", "s", ".", "Type", ")", "\n", "}" ]
// String returns a JSON representation of SchemaField.
[ "String", "returns", "a", "JSON", "representation", "of", "SchemaField", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L589-L591
14,794
elodina/go-avro
schema.go
Prop
func (s *ArraySchema) Prop(key string) (interface{}, bool) { if s.Properties != nil { if prop, ok := s.Properties[key]; ok { return prop, true } } return nil, false }
go
func (s *ArraySchema) Prop(key string) (interface{}, bool) { if s.Properties != nil { if prop, ok := s.Properties[key]; ok { return prop, true } } return nil, false }
[ "func", "(", "s", "*", "ArraySchema", ")", "Prop", "(", "key", "string", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "if", "s", ".", "Properties", "!=", "nil", "{", "if", "prop", ",", "ok", ":=", "s", ".", "Properties", "[", "key", "]", ";", "ok", "{", "return", "prop", ",", "true", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "false", "\n", "}" ]
// Prop gets a custom non-reserved property from this schema and a bool representing if it exists.
[ "Prop", "gets", "a", "custom", "non", "-", "reserved", "property", "from", "this", "schema", "and", "a", "bool", "representing", "if", "it", "exists", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L684-L692
14,795
elodina/go-avro
schema.go
String
func (s *MapSchema) String() string { bytes, err := json.MarshalIndent(s, "", " ") if err != nil { panic(err) } return string(bytes) }
go
func (s *MapSchema) String() string { bytes, err := json.MarshalIndent(s, "", " ") if err != nil { panic(err) } return string(bytes) }
[ "func", "(", "s", "*", "MapSchema", ")", "String", "(", ")", "string", "{", "bytes", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "s", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "string", "(", "bytes", ")", "\n", "}" ]
// String returns a JSON representation of MapSchema.
[ "String", "returns", "a", "JSON", "representation", "of", "MapSchema", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L720-L727
14,796
elodina/go-avro
schema.go
String
func (s *UnionSchema) String() string { bytes, err := json.MarshalIndent(s, "", " ") if err != nil { panic(err) } return fmt.Sprintf(`{"type": %s}`, string(bytes)) }
go
func (s *UnionSchema) String() string { bytes, err := json.MarshalIndent(s, "", " ") if err != nil { panic(err) } return fmt.Sprintf(`{"type": %s}`, string(bytes)) }
[ "func", "(", "s", "*", "UnionSchema", ")", "String", "(", ")", "string", "{", "bytes", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "s", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "`{\"type\": %s}`", ",", "string", "(", "bytes", ")", ")", "\n", "}" ]
// String returns a JSON representation of UnionSchema.
[ "String", "returns", "a", "JSON", "representation", "of", "UnionSchema", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L773-L780
14,797
elodina/go-avro
schema.go
GetType
func (s *UnionSchema) GetType(v reflect.Value) int { if s.Types != nil { for i := range s.Types { if t := s.Types[i]; t.Validate(v) { return i } } } return -1 }
go
func (s *UnionSchema) GetType(v reflect.Value) int { if s.Types != nil { for i := range s.Types { if t := s.Types[i]; t.Validate(v) { return i } } } return -1 }
[ "func", "(", "s", "*", "UnionSchema", ")", "GetType", "(", "v", "reflect", ".", "Value", ")", "int", "{", "if", "s", ".", "Types", "!=", "nil", "{", "for", "i", ":=", "range", "s", ".", "Types", "{", "if", "t", ":=", "s", ".", "Types", "[", "i", "]", ";", "t", ".", "Validate", "(", "v", ")", "{", "return", "i", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", "\n", "}" ]
// GetType gets the index of actual union type for a given value.
[ "GetType", "gets", "the", "index", "of", "actual", "union", "type", "for", "a", "given", "value", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L798-L808
14,798
elodina/go-avro
schema.go
GetFullName
func GetFullName(schema Schema) string { switch sch := schema.(type) { case *RecordSchema: return getFullName(sch.GetName(), sch.Namespace) case *EnumSchema: return getFullName(sch.GetName(), sch.Namespace) case *FixedSchema: return getFullName(sch.GetName(), sch.Namespace) default: return schema.GetName() } }
go
func GetFullName(schema Schema) string { switch sch := schema.(type) { case *RecordSchema: return getFullName(sch.GetName(), sch.Namespace) case *EnumSchema: return getFullName(sch.GetName(), sch.Namespace) case *FixedSchema: return getFullName(sch.GetName(), sch.Namespace) default: return schema.GetName() } }
[ "func", "GetFullName", "(", "schema", "Schema", ")", "string", "{", "switch", "sch", ":=", "schema", ".", "(", "type", ")", "{", "case", "*", "RecordSchema", ":", "return", "getFullName", "(", "sch", ".", "GetName", "(", ")", ",", "sch", ".", "Namespace", ")", "\n", "case", "*", "EnumSchema", ":", "return", "getFullName", "(", "sch", ".", "GetName", "(", ")", ",", "sch", ".", "Namespace", ")", "\n", "case", "*", "FixedSchema", ":", "return", "getFullName", "(", "sch", ".", "GetName", "(", ")", ",", "sch", ".", "Namespace", ")", "\n", "default", ":", "return", "schema", ".", "GetName", "(", ")", "\n", "}", "\n", "}" ]
// GetFullName returns a fully-qualified name for a schema if possible. The format is namespace.name.
[ "GetFullName", "returns", "a", "fully", "-", "qualified", "name", "for", "a", "schema", "if", "possible", ".", "The", "format", "is", "namespace", ".", "name", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L886-L897
14,799
elodina/go-avro
schema.go
ParseSchemaFile
func ParseSchemaFile(file string) (Schema, error) { fileContents, err := ioutil.ReadFile(file) if err != nil { return nil, err } return ParseSchema(string(fileContents)) }
go
func ParseSchemaFile(file string) (Schema, error) { fileContents, err := ioutil.ReadFile(file) if err != nil { return nil, err } return ParseSchema(string(fileContents)) }
[ "func", "ParseSchemaFile", "(", "file", "string", ")", "(", "Schema", ",", "error", ")", "{", "fileContents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "ParseSchema", "(", "string", "(", "fileContents", ")", ")", "\n", "}" ]
// ParseSchemaFile parses a given file. // May return an error if schema is not parsable or file does not exist.
[ "ParseSchemaFile", "parses", "a", "given", "file", ".", "May", "return", "an", "error", "if", "schema", "is", "not", "parsable", "or", "file", "does", "not", "exist", "." ]
0c8185d9a3ba82aeac98db3313a268a5b6df99b5
https://github.com/elodina/go-avro/blob/0c8185d9a3ba82aeac98db3313a268a5b6df99b5/schema.go#L901-L908