repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
linkedin/goavro
ocf_reader.go
SkipThisBlockAndReset
func (ocfr *OCFReader) SkipThisBlockAndReset() { // ??? is it an error to call method unless the reader has had an error ocfr.remainingBlockItems = 0 ocfr.block = ocfr.block[:0] ocfr.rerr = nil }
go
func (ocfr *OCFReader) SkipThisBlockAndReset() { // ??? is it an error to call method unless the reader has had an error ocfr.remainingBlockItems = 0 ocfr.block = ocfr.block[:0] ocfr.rerr = nil }
[ "func", "(", "ocfr", "*", "OCFReader", ")", "SkipThisBlockAndReset", "(", ")", "{", "// ??? is it an error to call method unless the reader has had an error", "ocfr", ".", "remainingBlockItems", "=", "0", "\n", "ocfr", ".", "block", "=", "ocfr", ".", "block", "[", "...
// SkipThisBlockAndReset can be called after an error occurs while reading or // decoding datum values from an OCF stream. OCF specifies each OCF stream // contain one or more blocks of data. Each block consists of a block count, the // number of bytes for the block, followed be the possibly compressed // block. Inside each decompressed block is all of the binary encoded datum // values concatenated together. In other words, OCF framing is at a block level // rather than a datum level. If there is an error while reading or decoding a // datum, the reader is not able to skip to the next datum value, because OCF // does not have any markers for where each datum ends and the next one // begins. Therefore, the reader is only able to skip this datum value and all // subsequent datum values in the current block, move to the next block and // start decoding datum values there.
[ "SkipThisBlockAndReset", "can", "be", "called", "after", "an", "error", "occurs", "while", "reading", "or", "decoding", "datum", "values", "from", "an", "OCF", "stream", ".", "OCF", "specifies", "each", "OCF", "stream", "contain", "one", "or", "more", "blocks"...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/ocf_reader.go#L258-L263
train
linkedin/goavro
text.go
advanceAndConsume
func advanceAndConsume(buf []byte, expected byte) ([]byte, error) { var err error if buf, err = advanceToNonWhitespace(buf); err != nil { return nil, err } if actual := buf[0]; actual != expected { return nil, fmt.Errorf("expected: %q; actual: %q", expected, actual) } return buf[1:], nil }
go
func advanceAndConsume(buf []byte, expected byte) ([]byte, error) { var err error if buf, err = advanceToNonWhitespace(buf); err != nil { return nil, err } if actual := buf[0]; actual != expected { return nil, fmt.Errorf("expected: %q; actual: %q", expected, actual) } return buf[1:], nil }
[ "func", "advanceAndConsume", "(", "buf", "[", "]", "byte", ",", "expected", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "buf", ",", "err", "=", "advanceToNonWhitespace", "(", "buf", ")", ";", "err", ...
// advanceAndConsume advances to non whitespace and returns an error if the next // non whitespace byte is not what is expected.
[ "advanceAndConsume", "advances", "to", "non", "whitespace", "and", "returns", "an", "error", "if", "the", "next", "non", "whitespace", "byte", "is", "not", "what", "is", "expected", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/text.go#L20-L29
train
linkedin/goavro
text.go
advanceToNonWhitespace
func advanceToNonWhitespace(buf []byte) ([]byte, error) { for i, b := range buf { if !unicode.IsSpace(rune(b)) { return buf[i:], nil } } return nil, io.ErrShortBuffer }
go
func advanceToNonWhitespace(buf []byte) ([]byte, error) { for i, b := range buf { if !unicode.IsSpace(rune(b)) { return buf[i:], nil } } return nil, io.ErrShortBuffer }
[ "func", "advanceToNonWhitespace", "(", "buf", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "i", ",", "b", ":=", "range", "buf", "{", "if", "!", "unicode", ".", "IsSpace", "(", "rune", "(", "b", ")", ")", "{", "re...
// advanceToNonWhitespace consumes bytes from buf until non-whitespace character // is found. It returns error when no more bytes remain, because its purpose is // to scan ahead to the next non-whitespace character.
[ "advanceToNonWhitespace", "consumes", "bytes", "from", "buf", "until", "non", "-", "whitespace", "character", "is", "found", ".", "It", "returns", "error", "when", "no", "more", "bytes", "remain", "because", "its", "purpose", "is", "to", "scan", "ahead", "to",...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/text.go#L34-L41
train
linkedin/goavro
ocf_writer.go
NewOCFWriter
func NewOCFWriter(config OCFConfig) (*OCFWriter, error) { var err error ocf := &OCFWriter{iow: config.W} switch config.W.(type) { case nil: return nil, errors.New("cannot create OCFWriter when W is nil") case *os.File: file := config.W.(*os.File) stat, err := file.Stat() if err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } // NOTE: When upstream provides a new file, it will already exist but // have a size of 0 bytes. if stat.Size() > 0 { // attempt to read existing OCF header if ocf.header, err = readOCFHeader(file); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } // prepare for appending data to existing OCF if err = ocf.quickScanToTail(file); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } return ocf, nil // happy case for appending to existing OCF } } // create new OCF header based on configuration parameters if ocf.header, err = newOCFHeader(config); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } if err = writeOCFHeader(ocf.header, config.W); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } return ocf, nil // another happy case for creation of new OCF }
go
func NewOCFWriter(config OCFConfig) (*OCFWriter, error) { var err error ocf := &OCFWriter{iow: config.W} switch config.W.(type) { case nil: return nil, errors.New("cannot create OCFWriter when W is nil") case *os.File: file := config.W.(*os.File) stat, err := file.Stat() if err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } // NOTE: When upstream provides a new file, it will already exist but // have a size of 0 bytes. if stat.Size() > 0 { // attempt to read existing OCF header if ocf.header, err = readOCFHeader(file); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } // prepare for appending data to existing OCF if err = ocf.quickScanToTail(file); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } return ocf, nil // happy case for appending to existing OCF } } // create new OCF header based on configuration parameters if ocf.header, err = newOCFHeader(config); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } if err = writeOCFHeader(ocf.header, config.W); err != nil { return nil, fmt.Errorf("cannot create OCFWriter: %s", err) } return ocf, nil // another happy case for creation of new OCF }
[ "func", "NewOCFWriter", "(", "config", "OCFConfig", ")", "(", "*", "OCFWriter", ",", "error", ")", "{", "var", "err", "error", "\n", "ocf", ":=", "&", "OCFWriter", "{", "iow", ":", "config", ".", "W", "}", "\n\n", "switch", "config", ".", "W", ".", ...
// NewOCFWriter returns a new OCFWriter instance that may be used for appending // binary Avro data, either by appending to an existing OCF file or creating a // new OCF file.
[ "NewOCFWriter", "returns", "a", "new", "OCFWriter", "instance", "that", "may", "be", "used", "for", "appending", "binary", "Avro", "data", "either", "by", "appending", "to", "an", "existing", "OCF", "file", "or", "creating", "a", "new", "OCF", "file", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/ocf_writer.go#L71-L107
train
linkedin/goavro
ocf_writer.go
quickScanToTail
func (ocfw *OCFWriter) quickScanToTail(ior io.Reader) error { sync := make([]byte, ocfSyncLength) for { // Read and validate block count blockCount, err := longBinaryReader(ior) if err != nil { if err == io.EOF { return nil // merely end of file, rather than error } return fmt.Errorf("cannot read block count: %s", err) } if blockCount <= 0 { return fmt.Errorf("cannot read when block count is not greater than 0: %d", blockCount) } if blockCount > MaxBlockCount { return fmt.Errorf("cannot read when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } // Read block size blockSize, err := longBinaryReader(ior) if err != nil { return fmt.Errorf("cannot read block size: %s", err) } if blockSize <= 0 { return fmt.Errorf("cannot read when block size is not greater than 0: %d", blockSize) } if blockSize > MaxBlockSize { return fmt.Errorf("cannot read when block size exceeds MaxBlockSize: %d > %d", blockSize, MaxBlockSize) } // Advance reader to end of block if _, err = io.CopyN(ioutil.Discard, ior, blockSize); err != nil { return fmt.Errorf("cannot seek to next block: %s", err) } // Read and validate sync marker var n int if n, err = io.ReadFull(ior, sync); err != nil { return fmt.Errorf("cannot read sync marker: read %d out of %d bytes: %s", n, ocfSyncLength, err) } if !bytes.Equal(sync, ocfw.header.syncMarker[:]) { return fmt.Errorf("sync marker mismatch: %v != %v", sync, ocfw.header.syncMarker) } } }
go
func (ocfw *OCFWriter) quickScanToTail(ior io.Reader) error { sync := make([]byte, ocfSyncLength) for { // Read and validate block count blockCount, err := longBinaryReader(ior) if err != nil { if err == io.EOF { return nil // merely end of file, rather than error } return fmt.Errorf("cannot read block count: %s", err) } if blockCount <= 0 { return fmt.Errorf("cannot read when block count is not greater than 0: %d", blockCount) } if blockCount > MaxBlockCount { return fmt.Errorf("cannot read when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } // Read block size blockSize, err := longBinaryReader(ior) if err != nil { return fmt.Errorf("cannot read block size: %s", err) } if blockSize <= 0 { return fmt.Errorf("cannot read when block size is not greater than 0: %d", blockSize) } if blockSize > MaxBlockSize { return fmt.Errorf("cannot read when block size exceeds MaxBlockSize: %d > %d", blockSize, MaxBlockSize) } // Advance reader to end of block if _, err = io.CopyN(ioutil.Discard, ior, blockSize); err != nil { return fmt.Errorf("cannot seek to next block: %s", err) } // Read and validate sync marker var n int if n, err = io.ReadFull(ior, sync); err != nil { return fmt.Errorf("cannot read sync marker: read %d out of %d bytes: %s", n, ocfSyncLength, err) } if !bytes.Equal(sync, ocfw.header.syncMarker[:]) { return fmt.Errorf("sync marker mismatch: %v != %v", sync, ocfw.header.syncMarker) } } }
[ "func", "(", "ocfw", "*", "OCFWriter", ")", "quickScanToTail", "(", "ior", "io", ".", "Reader", ")", "error", "{", "sync", ":=", "make", "(", "[", "]", "byte", ",", "ocfSyncLength", ")", "\n", "for", "{", "// Read and validate block count", "blockCount", "...
// quickScanToTail advances the stream reader to the tail end of the // file. Rather than reading each encoded block, optionally decompressing it, // and then decoding it, this method reads the block count, ignoring it, then // reads the block size, then skips ahead to the followig block. It does this // repeatedly until attempts to read the file return io.EOF.
[ "quickScanToTail", "advances", "the", "stream", "reader", "to", "the", "tail", "end", "of", "the", "file", ".", "Rather", "than", "reading", "each", "encoded", "block", "optionally", "decompressing", "it", "and", "then", "decoding", "it", "this", "method", "re...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/ocf_writer.go#L114-L155
train
linkedin/goavro
ocf_writer.go
Append
func (ocfw *OCFWriter) Append(data interface{}) error { arrayValues, err := convertArray(data) if err != nil { return err } // Chunk data so no block has more than MaxBlockCount items. for int64(len(arrayValues)) > MaxBlockCount { if err := ocfw.appendDataIntoBlock(arrayValues[:MaxBlockCount]); err != nil { return err } arrayValues = arrayValues[MaxBlockCount:] } return ocfw.appendDataIntoBlock(arrayValues) }
go
func (ocfw *OCFWriter) Append(data interface{}) error { arrayValues, err := convertArray(data) if err != nil { return err } // Chunk data so no block has more than MaxBlockCount items. for int64(len(arrayValues)) > MaxBlockCount { if err := ocfw.appendDataIntoBlock(arrayValues[:MaxBlockCount]); err != nil { return err } arrayValues = arrayValues[MaxBlockCount:] } return ocfw.appendDataIntoBlock(arrayValues) }
[ "func", "(", "ocfw", "*", "OCFWriter", ")", "Append", "(", "data", "interface", "{", "}", ")", "error", "{", "arrayValues", ",", "err", ":=", "convertArray", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", ...
// Append appends one or more data items to an OCF file in a block. If there are // more data items in the slice than MaxBlockCount allows, the data slice will // be chunked into multiple blocks, each not having more than MaxBlockCount // items.
[ "Append", "appends", "one", "or", "more", "data", "items", "to", "an", "OCF", "file", "in", "a", "block", ".", "If", "there", "are", "more", "data", "items", "in", "the", "slice", "than", "MaxBlockCount", "allows", "the", "data", "slice", "will", "be", ...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/ocf_writer.go#L161-L175
train
linkedin/goavro
ocf_writer.go
CompressionName
func (ocfw *OCFWriter) CompressionName() string { switch ocfw.header.compressionID { case compressionNull: return CompressionNullLabel case compressionDeflate: return CompressionDeflateLabel case compressionSnappy: return CompressionSnappyLabel default: return "should not get here: unrecognized compression algorithm" } }
go
func (ocfw *OCFWriter) CompressionName() string { switch ocfw.header.compressionID { case compressionNull: return CompressionNullLabel case compressionDeflate: return CompressionDeflateLabel case compressionSnappy: return CompressionSnappyLabel default: return "should not get here: unrecognized compression algorithm" } }
[ "func", "(", "ocfw", "*", "OCFWriter", ")", "CompressionName", "(", ")", "string", "{", "switch", "ocfw", ".", "header", ".", "compressionID", "{", "case", "compressionNull", ":", "return", "CompressionNullLabel", "\n", "case", "compressionDeflate", ":", "return...
// CompressionName returns the name of the compression algorithm used by // OCFWriter. This function provided because upstream may be appending to // existing OCF which uses a different compression algorithm than requested // during instantiation. the OCF file.
[ "CompressionName", "returns", "the", "name", "of", "the", "compression", "algorithm", "used", "by", "OCFWriter", ".", "This", "function", "provided", "because", "upstream", "may", "be", "appending", "to", "existing", "OCF", "which", "uses", "a", "different", "co...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/ocf_writer.go#L242-L253
train
linkedin/goavro
binaryReader.go
bytesBinaryReader
func bytesBinaryReader(ior io.Reader) ([]byte, error) { size, err := longBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read bytes: cannot read size: %s", err) } if size < 0 { return nil, fmt.Errorf("cannot read bytes: size is negative: %d", size) } if size > MaxBlockSize { return nil, fmt.Errorf("cannot read bytes: size exceeds MaxBlockSize: %d > %d", size, MaxBlockSize) } buf := make([]byte, size) _, err = io.ReadAtLeast(ior, buf, int(size)) if err != nil { return nil, fmt.Errorf("cannot read bytes: %s", err) } return buf, nil }
go
func bytesBinaryReader(ior io.Reader) ([]byte, error) { size, err := longBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read bytes: cannot read size: %s", err) } if size < 0 { return nil, fmt.Errorf("cannot read bytes: size is negative: %d", size) } if size > MaxBlockSize { return nil, fmt.Errorf("cannot read bytes: size exceeds MaxBlockSize: %d > %d", size, MaxBlockSize) } buf := make([]byte, size) _, err = io.ReadAtLeast(ior, buf, int(size)) if err != nil { return nil, fmt.Errorf("cannot read bytes: %s", err) } return buf, nil }
[ "func", "bytesBinaryReader", "(", "ior", "io", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "size", ",", "err", ":=", "longBinaryReader", "(", "ior", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", ...
// bytesBinaryReader reads bytes from io.Reader and returns byte slice of // specified size or the error encountered while trying to read those bytes.
[ "bytesBinaryReader", "reads", "bytes", "from", "io", ".", "Reader", "and", "returns", "byte", "slice", "of", "specified", "size", "or", "the", "error", "encountered", "while", "trying", "to", "read", "those", "bytes", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/binaryReader.go#L20-L37
train
linkedin/goavro
binaryReader.go
longBinaryReader
func longBinaryReader(ior io.Reader) (int64, error) { var value uint64 var shift uint var err error var b byte // NOTE: While benchmarks show it's more performant to invoke ReadByte when // available, testing whether a variable's data type implements a particular // method is quite slow too. So perform the test once, and branch to the // appropriate loop based on the results. if byteReader, ok := ior.(io.ByteReader); ok { for { if b, err = byteReader.ReadByte(); err != nil { return 0, err // NOTE: must send back unaltered error to detect io.EOF } value |= uint64(b&intMask) << shift if b&intFlag == 0 { return (int64(value>>1) ^ -int64(value&1)), nil } shift += 7 } } // NOTE: ior does not also implement io.ByteReader, so we must allocate a // byte slice with a single byte, and read each byte into the slice. buf := make([]byte, 1) for { if _, err = ior.Read(buf); err != nil { return 0, err // NOTE: must send back unaltered error to detect io.EOF } b = buf[0] value |= uint64(b&intMask) << shift if b&intFlag == 0 { return (int64(value>>1) ^ -int64(value&1)), nil } shift += 7 } }
go
func longBinaryReader(ior io.Reader) (int64, error) { var value uint64 var shift uint var err error var b byte // NOTE: While benchmarks show it's more performant to invoke ReadByte when // available, testing whether a variable's data type implements a particular // method is quite slow too. So perform the test once, and branch to the // appropriate loop based on the results. if byteReader, ok := ior.(io.ByteReader); ok { for { if b, err = byteReader.ReadByte(); err != nil { return 0, err // NOTE: must send back unaltered error to detect io.EOF } value |= uint64(b&intMask) << shift if b&intFlag == 0 { return (int64(value>>1) ^ -int64(value&1)), nil } shift += 7 } } // NOTE: ior does not also implement io.ByteReader, so we must allocate a // byte slice with a single byte, and read each byte into the slice. buf := make([]byte, 1) for { if _, err = ior.Read(buf); err != nil { return 0, err // NOTE: must send back unaltered error to detect io.EOF } b = buf[0] value |= uint64(b&intMask) << shift if b&intFlag == 0 { return (int64(value>>1) ^ -int64(value&1)), nil } shift += 7 } }
[ "func", "longBinaryReader", "(", "ior", "io", ".", "Reader", ")", "(", "int64", ",", "error", ")", "{", "var", "value", "uint64", "\n", "var", "shift", "uint", "\n", "var", "err", "error", "\n", "var", "b", "byte", "\n\n", "// NOTE: While benchmarks show i...
// longBinaryReader reads bytes from io.Reader until has complete long value, or // read error.
[ "longBinaryReader", "reads", "bytes", "from", "io", ".", "Reader", "until", "has", "complete", "long", "value", "or", "read", "error", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/binaryReader.go#L41-L79
train
linkedin/goavro
binaryReader.go
metadataBinaryReader
func metadataBinaryReader(ior io.Reader) (map[string][]byte, error) { var err error var value interface{} // block count and block size if value, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block count: %s", err) } blockCount := value.(int64) if blockCount < 0 { if blockCount == math.MinInt64 { // The minimum number for any signed numerical type can never be // made positive return nil, fmt.Errorf("cannot read map with block count: %d", blockCount) } // NOTE: A negative block count implies there is a long encoded block // size following the negative block count. We have no use for the block // size in this decoder, so we read and discard the value. blockCount = -blockCount // convert to its positive equivalent if _, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block size: %s", err) } } // Ensure block count does not exceed some sane value. if blockCount > MaxBlockCount { return nil, fmt.Errorf("cannot read map when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } // NOTE: While the attempt of a RAM optimization shown below is not // necessary, many encoders will encode all items in a single block. We can // optimize amount of RAM allocated by runtime for the array by initializing // the array for that number of items. mapValues := make(map[string][]byte, blockCount) for blockCount != 0 { // Decode `blockCount` datum values from buffer for i := int64(0); i < blockCount; i++ { // first decode the key string keyBytes, err := bytesBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read map key: %s", err) } key := string(keyBytes) if _, ok := mapValues[key]; ok { return nil, fmt.Errorf("cannot read map: duplicate key: %q", key) } // metadata values are always bytes buf, err := bytesBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read map value for key %q: %s", key, err) } mapValues[key] = buf } // Decode next blockCount from buffer, because there may be more blocks if value, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block count: %s", err) } blockCount = value.(int64) if blockCount < 0 { if blockCount == math.MinInt64 { // The minimum number for any signed numerical type can never be // made positive return nil, fmt.Errorf("cannot read map with block count: %d", blockCount) } // NOTE: A negative block count implies there is a long encoded // block size following the negative block count. We have no use for // the block size in this decoder, so we read and discard the value. blockCount = -blockCount // convert to its positive equivalent if _, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block size: %s", err) } } // Ensure block count does not exceed some sane value. if blockCount > MaxBlockCount { return nil, fmt.Errorf("cannot read map when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } } return mapValues, nil }
go
func metadataBinaryReader(ior io.Reader) (map[string][]byte, error) { var err error var value interface{} // block count and block size if value, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block count: %s", err) } blockCount := value.(int64) if blockCount < 0 { if blockCount == math.MinInt64 { // The minimum number for any signed numerical type can never be // made positive return nil, fmt.Errorf("cannot read map with block count: %d", blockCount) } // NOTE: A negative block count implies there is a long encoded block // size following the negative block count. We have no use for the block // size in this decoder, so we read and discard the value. blockCount = -blockCount // convert to its positive equivalent if _, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block size: %s", err) } } // Ensure block count does not exceed some sane value. if blockCount > MaxBlockCount { return nil, fmt.Errorf("cannot read map when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } // NOTE: While the attempt of a RAM optimization shown below is not // necessary, many encoders will encode all items in a single block. We can // optimize amount of RAM allocated by runtime for the array by initializing // the array for that number of items. mapValues := make(map[string][]byte, blockCount) for blockCount != 0 { // Decode `blockCount` datum values from buffer for i := int64(0); i < blockCount; i++ { // first decode the key string keyBytes, err := bytesBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read map key: %s", err) } key := string(keyBytes) if _, ok := mapValues[key]; ok { return nil, fmt.Errorf("cannot read map: duplicate key: %q", key) } // metadata values are always bytes buf, err := bytesBinaryReader(ior) if err != nil { return nil, fmt.Errorf("cannot read map value for key %q: %s", key, err) } mapValues[key] = buf } // Decode next blockCount from buffer, because there may be more blocks if value, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block count: %s", err) } blockCount = value.(int64) if blockCount < 0 { if blockCount == math.MinInt64 { // The minimum number for any signed numerical type can never be // made positive return nil, fmt.Errorf("cannot read map with block count: %d", blockCount) } // NOTE: A negative block count implies there is a long encoded // block size following the negative block count. We have no use for // the block size in this decoder, so we read and discard the value. blockCount = -blockCount // convert to its positive equivalent if _, err = longBinaryReader(ior); err != nil { return nil, fmt.Errorf("cannot read map block size: %s", err) } } // Ensure block count does not exceed some sane value. if blockCount > MaxBlockCount { return nil, fmt.Errorf("cannot read map when block count exceeds MaxBlockCount: %d > %d", blockCount, MaxBlockCount) } } return mapValues, nil }
[ "func", "metadataBinaryReader", "(", "ior", "io", ".", "Reader", ")", "(", "map", "[", "string", "]", "[", "]", "byte", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "value", "interface", "{", "}", "\n\n", "// block count and block size", "...
// metadataBinaryReader reads bytes from io.Reader until has entire map value, // or read error.
[ "metadataBinaryReader", "reads", "bytes", "from", "io", ".", "Reader", "until", "has", "entire", "map", "value", "or", "read", "error", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/binaryReader.go#L83-L160
train
linkedin/goavro
map.go
genericMapTextDecoder
func genericMapTextDecoder(buf []byte, defaultCodec *Codec, codecFromKey map[string]*Codec) (map[string]interface{}, []byte, error) { var value interface{} var err error var b byte lencodec := len(codecFromKey) mapValues := make(map[string]interface{}, lencodec) if buf, err = advanceAndConsume(buf, '{'); err != nil { return nil, nil, err } if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } // NOTE: Special case empty map if buf[0] == '}' { return mapValues, buf[1:], nil } // NOTE: Also terminates when read '}' byte. for len(buf) > 0 { // decode key string value, buf, err = stringNativeFromTextual(buf) if err != nil { return nil, nil, fmt.Errorf("cannot decode textual map: expected key: %s", err) } key := value.(string) // Is key already used? if _, ok := mapValues[key]; ok { return nil, nil, fmt.Errorf("cannot decode textual map: duplicate key: %q", key) } // Find a codec for the key fieldCodec := codecFromKey[key] if fieldCodec == nil { fieldCodec = defaultCodec } if fieldCodec == nil { return nil, nil, fmt.Errorf("cannot decode textual map: cannot determine codec: %q", key) } // decode colon if buf, err = advanceAndConsume(buf, ':'); err != nil { return nil, nil, err } // decode value if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } value, buf, err = fieldCodec.nativeFromTextual(buf) if err != nil { return nil, nil, err } // set map value for key mapValues[key] = value // either comma or closing curly brace if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } switch b = buf[0]; b { case '}': return mapValues, buf[1:], nil case ',': // no-op default: return nil, nil, fmt.Errorf("cannot decode textual map: expected ',' or '}'; received: %q", b) } // NOTE: consume comma from above if buf, _ = advanceToNonWhitespace(buf[1:]); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } } return nil, nil, io.ErrShortBuffer }
go
func genericMapTextDecoder(buf []byte, defaultCodec *Codec, codecFromKey map[string]*Codec) (map[string]interface{}, []byte, error) { var value interface{} var err error var b byte lencodec := len(codecFromKey) mapValues := make(map[string]interface{}, lencodec) if buf, err = advanceAndConsume(buf, '{'); err != nil { return nil, nil, err } if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } // NOTE: Special case empty map if buf[0] == '}' { return mapValues, buf[1:], nil } // NOTE: Also terminates when read '}' byte. for len(buf) > 0 { // decode key string value, buf, err = stringNativeFromTextual(buf) if err != nil { return nil, nil, fmt.Errorf("cannot decode textual map: expected key: %s", err) } key := value.(string) // Is key already used? if _, ok := mapValues[key]; ok { return nil, nil, fmt.Errorf("cannot decode textual map: duplicate key: %q", key) } // Find a codec for the key fieldCodec := codecFromKey[key] if fieldCodec == nil { fieldCodec = defaultCodec } if fieldCodec == nil { return nil, nil, fmt.Errorf("cannot decode textual map: cannot determine codec: %q", key) } // decode colon if buf, err = advanceAndConsume(buf, ':'); err != nil { return nil, nil, err } // decode value if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } value, buf, err = fieldCodec.nativeFromTextual(buf) if err != nil { return nil, nil, err } // set map value for key mapValues[key] = value // either comma or closing curly brace if buf, _ = advanceToNonWhitespace(buf); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } switch b = buf[0]; b { case '}': return mapValues, buf[1:], nil case ',': // no-op default: return nil, nil, fmt.Errorf("cannot decode textual map: expected ',' or '}'; received: %q", b) } // NOTE: consume comma from above if buf, _ = advanceToNonWhitespace(buf[1:]); len(buf) == 0 { return nil, nil, io.ErrShortBuffer } } return nil, nil, io.ErrShortBuffer }
[ "func", "genericMapTextDecoder", "(", "buf", "[", "]", "byte", ",", "defaultCodec", "*", "Codec", ",", "codecFromKey", "map", "[", "string", "]", "*", "Codec", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "[", "]", "byte", ",", "e...
// genericMapTextDecoder decodes a JSON text blob to a native Go map, using the // codecs from codecFromKey, and if a key is not found in that map, from // defaultCodec if provided. If defaultCodec is nil, this function returns an // error if it encounters a map key that is not present in codecFromKey. If // codecFromKey is nil, every map value will be decoded using defaultCodec, if // possible.
[ "genericMapTextDecoder", "decodes", "a", "JSON", "text", "blob", "to", "a", "native", "Go", "map", "using", "the", "codecs", "from", "codecFromKey", "and", "if", "a", "key", "is", "not", "found", "in", "that", "map", "from", "defaultCodec", "if", "provided",...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/map.go#L158-L229
train
linkedin/goavro
map.go
genericMapTextEncoder
func genericMapTextEncoder(buf []byte, datum interface{}, defaultCodec *Codec, codecFromKey map[string]*Codec) ([]byte, error) { mapValues, err := convertMap(datum) if err != nil { return nil, fmt.Errorf("cannot encode textual map: %s", err) } var atLeastOne bool buf = append(buf, '{') for key, value := range mapValues { atLeastOne = true // Find a codec for the key fieldCodec := codecFromKey[key] if fieldCodec == nil { fieldCodec = defaultCodec } if fieldCodec == nil { return nil, fmt.Errorf("cannot encode textual map: cannot determine codec: %q", key) } // Encode key string buf, err = stringTextualFromNative(buf, key) if err != nil { return nil, err } buf = append(buf, ':') // Encode value buf, err = fieldCodec.textualFromNative(buf, value) if err != nil { // field was specified in datum; therefore its value was invalid return nil, fmt.Errorf("cannot encode textual map: value for %q does not match its schema: %s", key, err) } buf = append(buf, ',') } if atLeastOne { return append(buf[:len(buf)-1], '}'), nil } return append(buf, '}'), nil }
go
func genericMapTextEncoder(buf []byte, datum interface{}, defaultCodec *Codec, codecFromKey map[string]*Codec) ([]byte, error) { mapValues, err := convertMap(datum) if err != nil { return nil, fmt.Errorf("cannot encode textual map: %s", err) } var atLeastOne bool buf = append(buf, '{') for key, value := range mapValues { atLeastOne = true // Find a codec for the key fieldCodec := codecFromKey[key] if fieldCodec == nil { fieldCodec = defaultCodec } if fieldCodec == nil { return nil, fmt.Errorf("cannot encode textual map: cannot determine codec: %q", key) } // Encode key string buf, err = stringTextualFromNative(buf, key) if err != nil { return nil, err } buf = append(buf, ':') // Encode value buf, err = fieldCodec.textualFromNative(buf, value) if err != nil { // field was specified in datum; therefore its value was invalid return nil, fmt.Errorf("cannot encode textual map: value for %q does not match its schema: %s", key, err) } buf = append(buf, ',') } if atLeastOne { return append(buf[:len(buf)-1], '}'), nil } return append(buf, '}'), nil }
[ "func", "genericMapTextEncoder", "(", "buf", "[", "]", "byte", ",", "datum", "interface", "{", "}", ",", "defaultCodec", "*", "Codec", ",", "codecFromKey", "map", "[", "string", "]", "*", "Codec", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "...
// genericMapTextEncoder encodes a native Go map to a JSON text blob, using the // codecs from codecFromKey, and if a key is not found in that map, from // defaultCodec if provided. If defaultCodec is nil, this function returns an // error if it encounters a map key that is not present in codecFromKey. If // codecFromKey is nil, every map value will be encoded using defaultCodec, if // possible.
[ "genericMapTextEncoder", "encodes", "a", "native", "Go", "map", "to", "a", "JSON", "text", "blob", "using", "the", "codecs", "from", "codecFromKey", "and", "if", "a", "key", "is", "not", "found", "in", "that", "map", "from", "defaultCodec", "if", "provided",...
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/map.go#L237-L277
train
linkedin/goavro
codec.go
buildCodec
func buildCodec(st map[string]*Codec, enclosingNamespace string, schema interface{}) (*Codec, error) { switch schemaType := schema.(type) { case map[string]interface{}: return buildCodecForTypeDescribedByMap(st, enclosingNamespace, schemaType) case string: return buildCodecForTypeDescribedByString(st, enclosingNamespace, schemaType, nil) case []interface{}: return buildCodecForTypeDescribedBySlice(st, enclosingNamespace, schemaType) default: return nil, fmt.Errorf("unknown schema type: %T", schema) } }
go
func buildCodec(st map[string]*Codec, enclosingNamespace string, schema interface{}) (*Codec, error) { switch schemaType := schema.(type) { case map[string]interface{}: return buildCodecForTypeDescribedByMap(st, enclosingNamespace, schemaType) case string: return buildCodecForTypeDescribedByString(st, enclosingNamespace, schemaType, nil) case []interface{}: return buildCodecForTypeDescribedBySlice(st, enclosingNamespace, schemaType) default: return nil, fmt.Errorf("unknown schema type: %T", schema) } }
[ "func", "buildCodec", "(", "st", "map", "[", "string", "]", "*", "Codec", ",", "enclosingNamespace", "string", ",", "schema", "interface", "{", "}", ")", "(", "*", "Codec", ",", "error", ")", "{", "switch", "schemaType", ":=", "schema", ".", "(", "type...
// convert a schema data structure to a codec, prefixing with specified // namespace
[ "convert", "a", "schema", "data", "structure", "to", "a", "codec", "prefixing", "with", "specified", "namespace" ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/codec.go#L445-L456
train
linkedin/goavro
codec.go
buildCodecForTypeDescribedByMap
func buildCodecForTypeDescribedByMap(st map[string]*Codec, enclosingNamespace string, schemaMap map[string]interface{}) (*Codec, error) { t, ok := schemaMap["type"] if !ok { return nil, fmt.Errorf("missing type: %v", schemaMap) } switch v := t.(type) { case string: // Already defined types may be abbreviated with its string name. // EXAMPLE: "type":"array" // EXAMPLE: "type":"enum" // EXAMPLE: "type":"fixed" // EXAMPLE: "type":"int" // EXAMPLE: "type":"record" // EXAMPLE: "type":"somePreviouslyDefinedCustomTypeString" return buildCodecForTypeDescribedByString(st, enclosingNamespace, v, schemaMap) case map[string]interface{}: return buildCodecForTypeDescribedByMap(st, enclosingNamespace, v) case []interface{}: return buildCodecForTypeDescribedBySlice(st, enclosingNamespace, v) default: return nil, fmt.Errorf("type ought to be either string, map[string]interface{}, or []interface{}; received: %T", t) } }
go
func buildCodecForTypeDescribedByMap(st map[string]*Codec, enclosingNamespace string, schemaMap map[string]interface{}) (*Codec, error) { t, ok := schemaMap["type"] if !ok { return nil, fmt.Errorf("missing type: %v", schemaMap) } switch v := t.(type) { case string: // Already defined types may be abbreviated with its string name. // EXAMPLE: "type":"array" // EXAMPLE: "type":"enum" // EXAMPLE: "type":"fixed" // EXAMPLE: "type":"int" // EXAMPLE: "type":"record" // EXAMPLE: "type":"somePreviouslyDefinedCustomTypeString" return buildCodecForTypeDescribedByString(st, enclosingNamespace, v, schemaMap) case map[string]interface{}: return buildCodecForTypeDescribedByMap(st, enclosingNamespace, v) case []interface{}: return buildCodecForTypeDescribedBySlice(st, enclosingNamespace, v) default: return nil, fmt.Errorf("type ought to be either string, map[string]interface{}, or []interface{}; received: %T", t) } }
[ "func", "buildCodecForTypeDescribedByMap", "(", "st", "map", "[", "string", "]", "*", "Codec", ",", "enclosingNamespace", "string", ",", "schemaMap", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "Codec", ",", "error", ")", "{", "t", "...
// Reach into the map, grabbing its "type". Use that to create the codec.
[ "Reach", "into", "the", "map", "grabbing", "its", "type", ".", "Use", "that", "to", "create", "the", "codec", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/codec.go#L459-L481
train
linkedin/goavro
codec.go
registerNewCodec
func registerNewCodec(st map[string]*Codec, schemaMap map[string]interface{}, enclosingNamespace string) (*Codec, error) { n, err := newNameFromSchemaMap(enclosingNamespace, schemaMap) if err != nil { return nil, err } c := &Codec{typeName: n} st[n.fullName] = c return c, nil }
go
func registerNewCodec(st map[string]*Codec, schemaMap map[string]interface{}, enclosingNamespace string) (*Codec, error) { n, err := newNameFromSchemaMap(enclosingNamespace, schemaMap) if err != nil { return nil, err } c := &Codec{typeName: n} st[n.fullName] = c return c, nil }
[ "func", "registerNewCodec", "(", "st", "map", "[", "string", "]", "*", "Codec", ",", "schemaMap", "map", "[", "string", "]", "interface", "{", "}", ",", "enclosingNamespace", "string", ")", "(", "*", "Codec", ",", "error", ")", "{", "n", ",", "err", ...
// notion of enclosing namespace changes when record, enum, or fixed create a // new namespace, for child objects.
[ "notion", "of", "enclosing", "namespace", "changes", "when", "record", "enum", "or", "fixed", "create", "a", "new", "namespace", "for", "child", "objects", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/codec.go#L532-L540
train
linkedin/goavro
name.go
newName
func newName(n, ns, ens string) (*name, error) { var nn name if index := strings.LastIndexByte(n, '.'); index > -1 { // inputName does contain a dot, so ignore everything else and use it as the full name nn.fullName = n nn.namespace = n[:index] } else { // inputName does not contain a dot, therefore is not the full name if ns != nullNamespace { // if namespace provided in the schema in the same schema level, use it nn.fullName = ns + "." + n nn.namespace = ns } else if ens != nullNamespace { // otherwise if enclosing namespace provided, use it nn.fullName = ens + "." + n nn.namespace = ens } else { // otherwise no namespace, so use null namespace, the empty string nn.fullName = n } } // verify all components of the full name for adherence to Avro naming rules for i, component := range strings.Split(nn.fullName, ".") { if i == 0 && RelaxedNameValidation && component == "" { continue } if err := checkNameComponent(component); err != nil { return nil, err } } return &nn, nil }
go
func newName(n, ns, ens string) (*name, error) { var nn name if index := strings.LastIndexByte(n, '.'); index > -1 { // inputName does contain a dot, so ignore everything else and use it as the full name nn.fullName = n nn.namespace = n[:index] } else { // inputName does not contain a dot, therefore is not the full name if ns != nullNamespace { // if namespace provided in the schema in the same schema level, use it nn.fullName = ns + "." + n nn.namespace = ns } else if ens != nullNamespace { // otherwise if enclosing namespace provided, use it nn.fullName = ens + "." + n nn.namespace = ens } else { // otherwise no namespace, so use null namespace, the empty string nn.fullName = n } } // verify all components of the full name for adherence to Avro naming rules for i, component := range strings.Split(nn.fullName, ".") { if i == 0 && RelaxedNameValidation && component == "" { continue } if err := checkNameComponent(component); err != nil { return nil, err } } return &nn, nil }
[ "func", "newName", "(", "n", ",", "ns", ",", "ens", "string", ")", "(", "*", "name", ",", "error", ")", "{", "var", "nn", "name", "\n\n", "if", "index", ":=", "strings", ".", "LastIndexByte", "(", "n", ",", "'.'", ")", ";", "index", ">", "-", "...
// newName returns a new Name instance after first ensuring the arguments do not // violate any of the Avro naming rules.
[ "newName", "returns", "a", "new", "Name", "instance", "after", "first", "ensuring", "the", "arguments", "do", "not", "violate", "any", "of", "the", "Avro", "naming", "rules", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/name.go#L69-L103
train
linkedin/goavro
name.go
short
func (n *name) short() string { if index := strings.LastIndexByte(n.fullName, '.'); index > -1 { return n.fullName[index+1:] } return n.fullName }
go
func (n *name) short() string { if index := strings.LastIndexByte(n.fullName, '.'); index > -1 { return n.fullName[index+1:] } return n.fullName }
[ "func", "(", "n", "*", "name", ")", "short", "(", ")", "string", "{", "if", "index", ":=", "strings", ".", "LastIndexByte", "(", "n", ".", "fullName", ",", "'.'", ")", ";", "index", ">", "-", "1", "{", "return", "n", ".", "fullName", "[", "index"...
// short returns the name without the prefixed namespace.
[ "short", "returns", "the", "name", "without", "the", "prefixed", "namespace", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/name.go#L137-L142
train
linkedin/goavro
canonical.go
pcfArray
func pcfArray(val []interface{}) (string, error) { items := make([]string, len(val)) for i, el := range val { p, err := parsingCanonicalForm(el) if err != nil { return "", err } items[i] = p } return "[" + strings.Join(items, ",") + "]", nil }
go
func pcfArray(val []interface{}) (string, error) { items := make([]string, len(val)) for i, el := range val { p, err := parsingCanonicalForm(el) if err != nil { return "", err } items[i] = p } return "[" + strings.Join(items, ",") + "]", nil }
[ "func", "pcfArray", "(", "val", "[", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "items", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "val", ")", ")", "\n", "for", "i", ",", "el", ":=", "range", "val", ...
// pcfArray returns the parsing canonical form for a JSON array.
[ "pcfArray", "returns", "the", "parsing", "canonical", "form", "for", "a", "JSON", "array", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/canonical.go#L56-L66
train
linkedin/goavro
canonical.go
pcfObject
func pcfObject(jsonMap map[string]interface{}) (string, error) { pairs := make(stringPairs, 0, len(jsonMap)) // Remember the namespace to fully qualify names later var namespace string if namespaceJSON, ok := jsonMap["namespace"]; ok { if namespaceStr, ok := namespaceJSON.(string); ok { // and it's value is string (otherwise invalid schema) namespace = namespaceStr } } for k, v := range jsonMap { // Reduce primitive schemas to their simple form. if len(jsonMap) == 1 && k == "type" { if t, ok := v.(string); ok { return "\"" + t + "\"", nil } } // Only keep relevant attributes (strip 'doc', 'alias', 'namespace') if _, ok := fieldOrder[k]; !ok { continue } // Add namespace to a non-qualified name. if k == "name" && namespace != "" { // Check if the name isn't already qualified. if t, ok := v.(string); ok && !strings.ContainsRune(t, '.') { v = namespace + "." + t } } // Only fixed type allows size, and we must convert a string size to a // float. if k == "size" { if s, ok := v.(string); ok { s, err := strconv.ParseUint(s, 10, 0) if err != nil { // should never get here because already validated schema return "", fmt.Errorf("Fixed size ought to be number greater than zero: %v", s) } v = float64(s) } } pk, err := parsingCanonicalForm(k) if err != nil { return "", err } pv, err := parsingCanonicalForm(v) if err != nil { return "", err } pairs = append(pairs, stringPair{k, pk + ":" + pv}) } // Sort keys by their order in specification. sort.Sort(byAvroFieldOrder(pairs)) return "{" + strings.Join(pairs.Bs(), ",") + "}", nil }
go
func pcfObject(jsonMap map[string]interface{}) (string, error) { pairs := make(stringPairs, 0, len(jsonMap)) // Remember the namespace to fully qualify names later var namespace string if namespaceJSON, ok := jsonMap["namespace"]; ok { if namespaceStr, ok := namespaceJSON.(string); ok { // and it's value is string (otherwise invalid schema) namespace = namespaceStr } } for k, v := range jsonMap { // Reduce primitive schemas to their simple form. if len(jsonMap) == 1 && k == "type" { if t, ok := v.(string); ok { return "\"" + t + "\"", nil } } // Only keep relevant attributes (strip 'doc', 'alias', 'namespace') if _, ok := fieldOrder[k]; !ok { continue } // Add namespace to a non-qualified name. if k == "name" && namespace != "" { // Check if the name isn't already qualified. if t, ok := v.(string); ok && !strings.ContainsRune(t, '.') { v = namespace + "." + t } } // Only fixed type allows size, and we must convert a string size to a // float. if k == "size" { if s, ok := v.(string); ok { s, err := strconv.ParseUint(s, 10, 0) if err != nil { // should never get here because already validated schema return "", fmt.Errorf("Fixed size ought to be number greater than zero: %v", s) } v = float64(s) } } pk, err := parsingCanonicalForm(k) if err != nil { return "", err } pv, err := parsingCanonicalForm(v) if err != nil { return "", err } pairs = append(pairs, stringPair{k, pk + ":" + pv}) } // Sort keys by their order in specification. sort.Sort(byAvroFieldOrder(pairs)) return "{" + strings.Join(pairs.Bs(), ",") + "}", nil }
[ "func", "pcfObject", "(", "jsonMap", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "pairs", ":=", "make", "(", "stringPairs", ",", "0", ",", "len", "(", "jsonMap", ")", ")", "\n\n", "// Remember the names...
// pcfObject returns the parsing canonical form for a JSON object.
[ "pcfObject", "returns", "the", "parsing", "canonical", "form", "for", "a", "JSON", "object", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/canonical.go#L69-L131
train
linkedin/goavro
canonical.go
Bs
func (sp *stringPairs) Bs() []string { items := make([]string, len(*sp)) for i, el := range *sp { items[i] = el.B } return items }
go
func (sp *stringPairs) Bs() []string { items := make([]string, len(*sp)) for i, el := range *sp { items[i] = el.B } return items }
[ "func", "(", "sp", "*", "stringPairs", ")", "Bs", "(", ")", "[", "]", "string", "{", "items", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "*", "sp", ")", ")", "\n", "for", "i", ",", "el", ":=", "range", "*", "sp", "{", "items", ...
// Bs returns an array of second values of an array of pairs.
[ "Bs", "returns", "an", "array", "of", "second", "values", "of", "an", "array", "of", "pairs", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/canonical.go#L143-L149
train
linkedin/goavro
logical_type.go
toSignedBytes
func toSignedBytes(n *big.Int) ([]byte, error) { switch n.Sign() { case 0: return []byte{0}, nil case 1: b := n.Bytes() if b[0]&0x80 > 0 { b = append([]byte{0}, b...) } return b, nil case -1: length := uint(n.BitLen()/8+1) * 8 b := new(big.Int).Add(n, new(big.Int).Lsh(one, length)).Bytes() // When the most significant bit is on a byte // boundary, we can get some extra significant // bits, so strip them off when that happens. if len(b) >= 2 && b[0] == 0xff && b[1]&0x80 != 0 { b = b[1:] } return b, nil } return nil, fmt.Errorf("toSignedBytes: error big.Int.Sign() returned unexpected value") }
go
func toSignedBytes(n *big.Int) ([]byte, error) { switch n.Sign() { case 0: return []byte{0}, nil case 1: b := n.Bytes() if b[0]&0x80 > 0 { b = append([]byte{0}, b...) } return b, nil case -1: length := uint(n.BitLen()/8+1) * 8 b := new(big.Int).Add(n, new(big.Int).Lsh(one, length)).Bytes() // When the most significant bit is on a byte // boundary, we can get some extra significant // bits, so strip them off when that happens. if len(b) >= 2 && b[0] == 0xff && b[1]&0x80 != 0 { b = b[1:] } return b, nil } return nil, fmt.Errorf("toSignedBytes: error big.Int.Sign() returned unexpected value") }
[ "func", "toSignedBytes", "(", "n", "*", "big", ".", "Int", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "switch", "n", ".", "Sign", "(", ")", "{", "case", "0", ":", "return", "[", "]", "byte", "{", "0", "}", ",", "nil", "\n", "case", ...
// toSignedBytes returns the big-endian two's complement // form of n.
[ "toSignedBytes", "returns", "the", "big", "-", "endian", "two", "s", "complement", "form", "of", "n", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/logical_type.go#L330-L352
train
linkedin/goavro
logical_type.go
toSignedFixedBytes
func toSignedFixedBytes(size uint) func(*big.Int) ([]byte, error) { return func(n *big.Int) ([]byte, error) { switch n.Sign() { case 0: return []byte{0}, nil case 1: b := n.Bytes() if b[0]&0x80 > 0 { b = append([]byte{0}, b...) } return padBytes(b, size), nil case -1: length := size * 8 b := new(big.Int).Add(n, new(big.Int).Lsh(one, length)).Bytes() // Unlike a variable length byte length we need the extra bits to meet byte length return b, nil } return nil, fmt.Errorf("toSignedBytes: error big.Int.Sign() returned unexpected value") } }
go
func toSignedFixedBytes(size uint) func(*big.Int) ([]byte, error) { return func(n *big.Int) ([]byte, error) { switch n.Sign() { case 0: return []byte{0}, nil case 1: b := n.Bytes() if b[0]&0x80 > 0 { b = append([]byte{0}, b...) } return padBytes(b, size), nil case -1: length := size * 8 b := new(big.Int).Add(n, new(big.Int).Lsh(one, length)).Bytes() // Unlike a variable length byte length we need the extra bits to meet byte length return b, nil } return nil, fmt.Errorf("toSignedBytes: error big.Int.Sign() returned unexpected value") } }
[ "func", "toSignedFixedBytes", "(", "size", "uint", ")", "func", "(", "*", "big", ".", "Int", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "func", "(", "n", "*", "big", ".", "Int", ")", "(", "[", "]", "byte", ",", "error", ")", ...
// toSignedFixedBytes returns the big-endian two's complement // form of n for a given length of bytes.
[ "toSignedFixedBytes", "returns", "the", "big", "-", "endian", "two", "s", "complement", "form", "of", "n", "for", "a", "given", "length", "of", "bytes", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/logical_type.go#L356-L375
train
linkedin/goavro
examples/nested/main.go
ToStringMap
func (u *User) ToStringMap() map[string]interface{} { datumIn := map[string]interface{}{ "FirstName": string(u.FirstName), "LastName": string(u.LastName), } if len(u.Errors) > 0 { datumIn["Errors"] = goavro.Union("array", u.Errors) } else { datumIn["Errors"] = goavro.Union("null", nil) } if u.Address != nil { addDatum := map[string]interface{}{ "Address1": string(u.Address.Address1), "City": string(u.Address.City), "State": string(u.Address.State), "Zip": int(u.Address.Zip), } if u.Address.Address2 != "" { addDatum["Address2"] = goavro.Union("string", u.Address.Address2) } else { addDatum["Address2"] = goavro.Union("null", nil) } //important need namespace and record name datumIn["Address"] = goavro.Union("my.namespace.com.address", addDatum) } else { datumIn["Address"] = goavro.Union("null", nil) } return datumIn }
go
func (u *User) ToStringMap() map[string]interface{} { datumIn := map[string]interface{}{ "FirstName": string(u.FirstName), "LastName": string(u.LastName), } if len(u.Errors) > 0 { datumIn["Errors"] = goavro.Union("array", u.Errors) } else { datumIn["Errors"] = goavro.Union("null", nil) } if u.Address != nil { addDatum := map[string]interface{}{ "Address1": string(u.Address.Address1), "City": string(u.Address.City), "State": string(u.Address.State), "Zip": int(u.Address.Zip), } if u.Address.Address2 != "" { addDatum["Address2"] = goavro.Union("string", u.Address.Address2) } else { addDatum["Address2"] = goavro.Union("null", nil) } //important need namespace and record name datumIn["Address"] = goavro.Union("my.namespace.com.address", addDatum) } else { datumIn["Address"] = goavro.Union("null", nil) } return datumIn }
[ "func", "(", "u", "*", "User", ")", "ToStringMap", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "datumIn", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "string", "(", "u", ".", "FirstName", ")"...
// ToStringMap returns a map representation of the User.
[ "ToStringMap", "returns", "a", "map", "representation", "of", "the", "User", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/examples/nested/main.go#L85-L117
train
linkedin/goavro
examples/nested/main.go
StringMapToUser
func StringMapToUser(data map[string]interface{}) *User { ind := &User{} for k, v := range data { switch k { case "FirstName": if value, ok := v.(string); ok { ind.FirstName = value } case "LastName": if value, ok := v.(string); ok { ind.LastName = value } case "Errors": if value, ok := v.(map[string]interface{}); ok { for _, item := range value["array"].([]interface{}) { ind.Errors = append(ind.Errors, item.(string)) } } case "Address": if vmap, ok := v.(map[string]interface{}); ok { //important need namespace and record name if cookieSMap, ok := vmap["my.namespace.com.address"].(map[string]interface{}); ok { add := &Address{} for k, v := range cookieSMap { switch k { case "Address1": if value, ok := v.(string); ok { add.Address1 = value } case "Address2": if value, ok := v.(string); ok { add.Address2 = value } case "City": if value, ok := v.(string); ok { add.City = value } case "Zip": if value, ok := v.(int); ok { add.Zip = value } } } ind.Address = add } } } } return ind }
go
func StringMapToUser(data map[string]interface{}) *User { ind := &User{} for k, v := range data { switch k { case "FirstName": if value, ok := v.(string); ok { ind.FirstName = value } case "LastName": if value, ok := v.(string); ok { ind.LastName = value } case "Errors": if value, ok := v.(map[string]interface{}); ok { for _, item := range value["array"].([]interface{}) { ind.Errors = append(ind.Errors, item.(string)) } } case "Address": if vmap, ok := v.(map[string]interface{}); ok { //important need namespace and record name if cookieSMap, ok := vmap["my.namespace.com.address"].(map[string]interface{}); ok { add := &Address{} for k, v := range cookieSMap { switch k { case "Address1": if value, ok := v.(string); ok { add.Address1 = value } case "Address2": if value, ok := v.(string); ok { add.Address2 = value } case "City": if value, ok := v.(string); ok { add.City = value } case "Zip": if value, ok := v.(int); ok { add.Zip = value } } } ind.Address = add } } } } return ind }
[ "func", "StringMapToUser", "(", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "*", "User", "{", "ind", ":=", "&", "User", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "data", "{", "switch", "k", "{", "case", "\"", "\"", ...
// StringMapToUser returns a User from a map representation of the User.
[ "StringMapToUser", "returns", "a", "User", "from", "a", "map", "representation", "of", "the", "User", "." ]
45f9a215035e4767b6a0848975ec3df73ed9c1b0
https://github.com/linkedin/goavro/blob/45f9a215035e4767b6a0848975ec3df73ed9c1b0/examples/nested/main.go#L120-L172
train
JamesClonk/vultr
lib/account_info.go
GetAccountInfo
func (c *Client) GetAccountInfo() (info AccountInfo, err error) { if err := c.get(`account/info`, &info); err != nil { return AccountInfo{}, err } return }
go
func (c *Client) GetAccountInfo() (info AccountInfo, err error) { if err := c.get(`account/info`, &info); err != nil { return AccountInfo{}, err } return }
[ "func", "(", "c", "*", "Client", ")", "GetAccountInfo", "(", ")", "(", "info", "AccountInfo", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`account/info`", ",", "&", "info", ")", ";", "err", "!=", "nil", "{", "return", ...
// GetAccountInfo retrieves the Vultr account information about current balance, pending charges, etc..
[ "GetAccountInfo", "retrieves", "the", "Vultr", "account", "information", "about", "current", "balance", "pending", "charges", "etc", ".." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/account_info.go#L18-L23
train
JamesClonk/vultr
lib/account_info.go
UnmarshalJSON
func (a *AccountInfo) UnmarshalJSON(data []byte) (err error) { if a == nil { *a = AccountInfo{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["balance"]) if len(value) == 0 || value == "<nil>" { value = "0" } b, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.Balance = b value = fmt.Sprintf("%v", fields["pending_charges"]) if len(value) == 0 || value == "<nil>" { value = "0" } pc, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.PendingCharges = pc value = fmt.Sprintf("%v", fields["last_payment_amount"]) if len(value) == 0 || value == "<nil>" { value = "0" } lpa, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.LastPaymentAmount = lpa a.LastPaymentDate = fmt.Sprintf("%v", fields["last_payment_date"]) return }
go
func (a *AccountInfo) UnmarshalJSON(data []byte) (err error) { if a == nil { *a = AccountInfo{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["balance"]) if len(value) == 0 || value == "<nil>" { value = "0" } b, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.Balance = b value = fmt.Sprintf("%v", fields["pending_charges"]) if len(value) == 0 || value == "<nil>" { value = "0" } pc, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.PendingCharges = pc value = fmt.Sprintf("%v", fields["last_payment_amount"]) if len(value) == 0 || value == "<nil>" { value = "0" } lpa, err := strconv.ParseFloat(value, 64) if err != nil { return err } a.LastPaymentAmount = lpa a.LastPaymentDate = fmt.Sprintf("%v", fields["last_payment_date"]) return }
[ "func", "(", "a", "*", "AccountInfo", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "if", "a", "==", "nil", "{", "*", "a", "=", "AccountInfo", "{", "}", "\n", "}", "\n\n", "var", "fields", "map", "[", ...
// UnmarshalJSON implements json.Unmarshaller on AccountInfo. // This is needed because the Vultr API is inconsistent in it's JSON responses for account info. // Some fields can change type, from JSON number to JSON string and vice-versa.
[ "UnmarshalJSON", "implements", "json", ".", "Unmarshaller", "on", "AccountInfo", ".", "This", "is", "needed", "because", "the", "Vultr", "API", "is", "inconsistent", "in", "it", "s", "JSON", "responses", "for", "account", "info", ".", "Some", "fields", "can", ...
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/account_info.go#L28-L71
train
JamesClonk/vultr
lib/os.go
GetOS
func (c *Client) GetOS() ([]OS, error) { var osMap map[string]OS if err := c.get(`os/list`, &osMap); err != nil { return nil, err } var osList []OS for _, os := range osMap { osList = append(osList, os) } sort.Sort(oses(osList)) return osList, nil }
go
func (c *Client) GetOS() ([]OS, error) { var osMap map[string]OS if err := c.get(`os/list`, &osMap); err != nil { return nil, err } var osList []OS for _, os := range osMap { osList = append(osList, os) } sort.Sort(oses(osList)) return osList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetOS", "(", ")", "(", "[", "]", "OS", ",", "error", ")", "{", "var", "osMap", "map", "[", "string", "]", "OS", "\n", "if", "err", ":=", "c", ".", "get", "(", "`os/list`", ",", "&", "osMap", ")", ";", ...
// GetOS returns a list of all available operating systems on Vultr
[ "GetOS", "returns", "a", "list", "of", "all", "available", "operating", "systems", "on", "Vultr" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/os.go#L25-L37
train
JamesClonk/vultr
cmd/cli.go
NewCLI
func NewCLI() *CLI { c := &CLI{cli.App("vultr", "A Vultr CLI")} apiKey = c.String(cli.StringOpt{ Name: "k api-key", Desc: "Vultr API-Key", EnvVar: "VULTR_API_KEY", HideValue: true, }) return c }
go
func NewCLI() *CLI { c := &CLI{cli.App("vultr", "A Vultr CLI")} apiKey = c.String(cli.StringOpt{ Name: "k api-key", Desc: "Vultr API-Key", EnvVar: "VULTR_API_KEY", HideValue: true, }) return c }
[ "func", "NewCLI", "(", ")", "*", "CLI", "{", "c", ":=", "&", "CLI", "{", "cli", ".", "App", "(", "\"", "\"", ",", "\"", "\"", ")", "}", "\n\n", "apiKey", "=", "c", ".", "String", "(", "cli", ".", "StringOpt", "{", "Name", ":", "\"", "\"", "...
// NewCLI initializes new command line interface
[ "NewCLI", "initializes", "new", "command", "line", "interface" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/cmd/cli.go#L13-L24
train
JamesClonk/vultr
lib/snapshots.go
GetSnapshots
func (c *Client) GetSnapshots() (snapshotList []Snapshot, err error) { var snapshotMap map[string]Snapshot if err := c.get(`snapshot/list`, &snapshotMap); err != nil { return nil, err } for _, snapshot := range snapshotMap { snapshotList = append(snapshotList, snapshot) } sort.Sort(snapshots(snapshotList)) return snapshotList, nil }
go
func (c *Client) GetSnapshots() (snapshotList []Snapshot, err error) { var snapshotMap map[string]Snapshot if err := c.get(`snapshot/list`, &snapshotMap); err != nil { return nil, err } for _, snapshot := range snapshotMap { snapshotList = append(snapshotList, snapshot) } sort.Sort(snapshots(snapshotList)) return snapshotList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetSnapshots", "(", ")", "(", "snapshotList", "[", "]", "Snapshot", ",", "err", "error", ")", "{", "var", "snapshotMap", "map", "[", "string", "]", "Snapshot", "\n", "if", "err", ":=", "c", ".", "get", "(", "`...
// GetSnapshots retrieves a list of all snapshots on Vultr account
[ "GetSnapshots", "retrieves", "a", "list", "of", "all", "snapshots", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/snapshots.go#L35-L46
train
JamesClonk/vultr
lib/snapshots.go
CreateSnapshot
func (c *Client) CreateSnapshot(id, description string) (Snapshot, error) { values := url.Values{ "SUBID": {id}, "description": {description}, } var snapshot Snapshot if err := c.post(`snapshot/create`, values, &snapshot); err != nil { return Snapshot{}, err } snapshot.Description = description return snapshot, nil }
go
func (c *Client) CreateSnapshot(id, description string) (Snapshot, error) { values := url.Values{ "SUBID": {id}, "description": {description}, } var snapshot Snapshot if err := c.post(`snapshot/create`, values, &snapshot); err != nil { return Snapshot{}, err } snapshot.Description = description return snapshot, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateSnapshot", "(", "id", ",", "description", "string", ")", "(", "Snapshot", ",", "error", ")", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", ...
// CreateSnapshot creates a new virtual machine snapshot
[ "CreateSnapshot", "creates", "a", "new", "virtual", "machine", "snapshot" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/snapshots.go#L49-L62
train
JamesClonk/vultr
lib/scripts.go
UnmarshalJSON
func (s *StartupScript) UnmarshalJSON(data []byte) (err error) { if s == nil { *s = StartupScript{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } s.ID = fmt.Sprintf("%v", fields["SCRIPTID"]) s.Name = fmt.Sprintf("%v", fields["name"]) s.Type = fmt.Sprintf("%v", fields["type"]) s.Content = fmt.Sprintf("%v", fields["script"]) return }
go
func (s *StartupScript) UnmarshalJSON(data []byte) (err error) { if s == nil { *s = StartupScript{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } s.ID = fmt.Sprintf("%v", fields["SCRIPTID"]) s.Name = fmt.Sprintf("%v", fields["name"]) s.Type = fmt.Sprintf("%v", fields["type"]) s.Content = fmt.Sprintf("%v", fields["script"]) return }
[ "func", "(", "s", "*", "StartupScript", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "if", "s", "==", "nil", "{", "*", "s", "=", "StartupScript", "{", "}", "\n", "}", "\n\n", "var", "fields", "map", "["...
// UnmarshalJSON implements json.Unmarshaller on StartupScript. // Necessary because the SCRIPTID field has inconsistent types.
[ "UnmarshalJSON", "implements", "json", ".", "Unmarshaller", "on", "StartupScript", ".", "Necessary", "because", "the", "SCRIPTID", "field", "has", "inconsistent", "types", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L29-L45
train
JamesClonk/vultr
lib/scripts.go
GetStartupScripts
func (c *Client) GetStartupScripts() (scripts []StartupScript, err error) { var scriptMap map[string]StartupScript if err := c.get(`startupscript/list`, &scriptMap); err != nil { return nil, err } for _, script := range scriptMap { if script.Type == "" { script.Type = "boot" // set default script type } scripts = append(scripts, script) } sort.Sort(startupscripts(scripts)) return scripts, nil }
go
func (c *Client) GetStartupScripts() (scripts []StartupScript, err error) { var scriptMap map[string]StartupScript if err := c.get(`startupscript/list`, &scriptMap); err != nil { return nil, err } for _, script := range scriptMap { if script.Type == "" { script.Type = "boot" // set default script type } scripts = append(scripts, script) } sort.Sort(startupscripts(scripts)) return scripts, nil }
[ "func", "(", "c", "*", "Client", ")", "GetStartupScripts", "(", ")", "(", "scripts", "[", "]", "StartupScript", ",", "err", "error", ")", "{", "var", "scriptMap", "map", "[", "string", "]", "StartupScript", "\n", "if", "err", ":=", "c", ".", "get", "...
// GetStartupScripts returns a list of all startup scripts on the current Vultr account
[ "GetStartupScripts", "returns", "a", "list", "of", "all", "startup", "scripts", "on", "the", "current", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L48-L62
train
JamesClonk/vultr
lib/scripts.go
GetStartupScript
func (c *Client) GetStartupScript(id string) (StartupScript, error) { scripts, err := c.GetStartupScripts() if err != nil { return StartupScript{}, err } for _, s := range scripts { if s.ID == id { return s, nil } } return StartupScript{}, nil }
go
func (c *Client) GetStartupScript(id string) (StartupScript, error) { scripts, err := c.GetStartupScripts() if err != nil { return StartupScript{}, err } for _, s := range scripts { if s.ID == id { return s, nil } } return StartupScript{}, nil }
[ "func", "(", "c", "*", "Client", ")", "GetStartupScript", "(", "id", "string", ")", "(", "StartupScript", ",", "error", ")", "{", "scripts", ",", "err", ":=", "c", ".", "GetStartupScripts", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "St...
// GetStartupScript returns the startup script with the given ID
[ "GetStartupScript", "returns", "the", "startup", "script", "with", "the", "given", "ID" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L65-L77
train
JamesClonk/vultr
lib/scripts.go
CreateStartupScript
func (c *Client) CreateStartupScript(name, content, scriptType string) (StartupScript, error) { values := url.Values{ "name": {name}, "script": {content}, "type": {scriptType}, } var script StartupScript if err := c.post(`startupscript/create`, values, &script); err != nil { return StartupScript{}, err } script.Name = name script.Content = content script.Type = scriptType return script, nil }
go
func (c *Client) CreateStartupScript(name, content, scriptType string) (StartupScript, error) { values := url.Values{ "name": {name}, "script": {content}, "type": {scriptType}, } var script StartupScript if err := c.post(`startupscript/create`, values, &script); err != nil { return StartupScript{}, err } script.Name = name script.Content = content script.Type = scriptType return script, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateStartupScript", "(", "name", ",", "content", ",", "scriptType", "string", ")", "(", "StartupScript", ",", "error", ")", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "name", "}", ",...
// CreateStartupScript creates a new startup script
[ "CreateStartupScript", "creates", "a", "new", "startup", "script" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L80-L96
train
JamesClonk/vultr
lib/scripts.go
UpdateStartupScript
func (c *Client) UpdateStartupScript(script StartupScript) error { values := url.Values{ "SCRIPTID": {script.ID}, } if script.Name != "" { values.Add("name", script.Name) } if script.Content != "" { values.Add("script", script.Content) } if err := c.post(`startupscript/update`, values, nil); err != nil { return err } return nil }
go
func (c *Client) UpdateStartupScript(script StartupScript) error { values := url.Values{ "SCRIPTID": {script.ID}, } if script.Name != "" { values.Add("name", script.Name) } if script.Content != "" { values.Add("script", script.Content) } if err := c.post(`startupscript/update`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "UpdateStartupScript", "(", "script", "StartupScript", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "script", ".", "ID", "}", ",", "}", "\n", "if", "script", ".", "Name", ...
// UpdateStartupScript updates an existing startup script
[ "UpdateStartupScript", "updates", "an", "existing", "startup", "script" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L99-L114
train
JamesClonk/vultr
lib/reservedip.go
UnmarshalJSON
func (i *IP) UnmarshalJSON(data []byte) (err error) { if i == nil { *i = IP{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["SUBID"]) if len(value) == 0 || value == "<nil>" || value == "0" { i.ID = "" } else { id, err := strconv.ParseFloat(value, 64) if err != nil { return err } i.ID = strconv.FormatFloat(id, 'f', -1, 64) } value = fmt.Sprintf("%v", fields["DCID"]) if len(value) == 0 || value == "<nil>" { value = "0" } region, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } i.RegionID = int(region) value = fmt.Sprintf("%v", fields["attached_SUBID"]) if len(value) == 0 || value == "<nil>" || value == "0" || value == "false" { i.AttachedTo = "" } else { attached, err := strconv.ParseFloat(value, 64) if err != nil { return err } i.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64) } value = fmt.Sprintf("%v", fields["subnet_size"]) if len(value) == 0 || value == "<nil>" { value = "0" } size, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } i.SubnetSize = int(size) i.IPType = fmt.Sprintf("%v", fields["ip_type"]) i.Subnet = fmt.Sprintf("%v", fields["subnet"]) i.Label = fmt.Sprintf("%v", fields["label"]) return }
go
func (i *IP) UnmarshalJSON(data []byte) (err error) { if i == nil { *i = IP{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["SUBID"]) if len(value) == 0 || value == "<nil>" || value == "0" { i.ID = "" } else { id, err := strconv.ParseFloat(value, 64) if err != nil { return err } i.ID = strconv.FormatFloat(id, 'f', -1, 64) } value = fmt.Sprintf("%v", fields["DCID"]) if len(value) == 0 || value == "<nil>" { value = "0" } region, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } i.RegionID = int(region) value = fmt.Sprintf("%v", fields["attached_SUBID"]) if len(value) == 0 || value == "<nil>" || value == "0" || value == "false" { i.AttachedTo = "" } else { attached, err := strconv.ParseFloat(value, 64) if err != nil { return err } i.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64) } value = fmt.Sprintf("%v", fields["subnet_size"]) if len(value) == 0 || value == "<nil>" { value = "0" } size, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } i.SubnetSize = int(size) i.IPType = fmt.Sprintf("%v", fields["ip_type"]) i.Subnet = fmt.Sprintf("%v", fields["subnet"]) i.Label = fmt.Sprintf("%v", fields["label"]) return }
[ "func", "(", "i", "*", "IP", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "if", "i", "==", "nil", "{", "*", "i", "=", "IP", "{", "}", "\n", "}", "\n\n", "var", "fields", "map", "[", "string", "]", ...
// UnmarshalJSON implements json.Unmarshaller on IP. // This is needed because the Vultr API is inconsistent in it's JSON responses. // Some fields can change type, from JSON number to JSON string and vice-versa.
[ "UnmarshalJSON", "implements", "json", ".", "Unmarshaller", "on", "IP", ".", "This", "is", "needed", "because", "the", "Vultr", "API", "is", "inconsistent", "in", "it", "s", "JSON", "responses", ".", "Some", "fields", "can", "change", "type", "from", "JSON",...
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L45-L102
train
JamesClonk/vultr
lib/reservedip.go
ListReservedIP
func (c *Client) ListReservedIP() ([]IP, error) { var ipMap map[string]IP err := c.get(`reservedip/list`, &ipMap) if err != nil { return nil, err } ipList := make([]IP, 0) for _, ip := range ipMap { ipList = append(ipList, ip) } sort.Sort(ips(ipList)) return ipList, nil }
go
func (c *Client) ListReservedIP() ([]IP, error) { var ipMap map[string]IP err := c.get(`reservedip/list`, &ipMap) if err != nil { return nil, err } ipList := make([]IP, 0) for _, ip := range ipMap { ipList = append(ipList, ip) } sort.Sort(ips(ipList)) return ipList, nil }
[ "func", "(", "c", "*", "Client", ")", "ListReservedIP", "(", ")", "(", "[", "]", "IP", ",", "error", ")", "{", "var", "ipMap", "map", "[", "string", "]", "IP", "\n\n", "err", ":=", "c", ".", "get", "(", "`reservedip/list`", ",", "&", "ipMap", ")"...
// ListReservedIP returns a list of all available reserved IPs on Vultr account
[ "ListReservedIP", "returns", "a", "list", "of", "all", "available", "reserved", "IPs", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L105-L119
train
JamesClonk/vultr
lib/reservedip.go
GetReservedIP
func (c *Client) GetReservedIP(id string) (IP, error) { var ipMap map[string]IP err := c.get(`reservedip/list`, &ipMap) if err != nil { return IP{}, err } if ip, ok := ipMap[id]; ok { return ip, nil } return IP{}, fmt.Errorf("IP with ID %v not found", id) }
go
func (c *Client) GetReservedIP(id string) (IP, error) { var ipMap map[string]IP err := c.get(`reservedip/list`, &ipMap) if err != nil { return IP{}, err } if ip, ok := ipMap[id]; ok { return ip, nil } return IP{}, fmt.Errorf("IP with ID %v not found", id) }
[ "func", "(", "c", "*", "Client", ")", "GetReservedIP", "(", "id", "string", ")", "(", "IP", ",", "error", ")", "{", "var", "ipMap", "map", "[", "string", "]", "IP", "\n\n", "err", ":=", "c", ".", "get", "(", "`reservedip/list`", ",", "&", "ipMap", ...
// GetReservedIP returns reserved IP with given ID
[ "GetReservedIP", "returns", "reserved", "IP", "with", "given", "ID" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L122-L133
train
JamesClonk/vultr
lib/reservedip.go
CreateReservedIP
func (c *Client) CreateReservedIP(regionID int, ipType string, label string) (string, error) { values := url.Values{ "DCID": {fmt.Sprintf("%v", regionID)}, "ip_type": {ipType}, } if len(label) > 0 { values.Add("label", label) } result := IP{} err := c.post(`reservedip/create`, values, &result) if err != nil { return "", err } return result.ID, nil }
go
func (c *Client) CreateReservedIP(regionID int, ipType string, label string) (string, error) { values := url.Values{ "DCID": {fmt.Sprintf("%v", regionID)}, "ip_type": {ipType}, } if len(label) > 0 { values.Add("label", label) } result := IP{} err := c.post(`reservedip/create`, values, &result) if err != nil { return "", err } return result.ID, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateReservedIP", "(", "regionID", "int", ",", "ipType", "string", ",", "label", "string", ")", "(", "string", ",", "error", ")", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "fmt", "...
// CreateReservedIP creates a new reserved IP on Vultr account
[ "CreateReservedIP", "creates", "a", "new", "reserved", "IP", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L136-L151
train
JamesClonk/vultr
lib/reservedip.go
AttachReservedIP
func (c *Client) AttachReservedIP(ip string, serverID string) error { values := url.Values{ "ip_address": {ip}, "attach_SUBID": {serverID}, } return c.post(`reservedip/attach`, values, nil) }
go
func (c *Client) AttachReservedIP(ip string, serverID string) error { values := url.Values{ "ip_address": {ip}, "attach_SUBID": {serverID}, } return c.post(`reservedip/attach`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "AttachReservedIP", "(", "ip", "string", ",", "serverID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "ip", "}", ",", "\"", "\"", ":", "{", "serverID", "}", "...
// AttachReservedIP attaches a reserved IP to a virtual machine
[ "AttachReservedIP", "attaches", "a", "reserved", "IP", "to", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L162-L168
train
JamesClonk/vultr
lib/reservedip.go
ConvertReservedIP
func (c *Client) ConvertReservedIP(serverID string, ip string) (string, error) { values := url.Values{ "SUBID": {serverID}, "ip_address": {ip}, } result := IP{} err := c.post(`reservedip/convert`, values, &result) if err != nil { return "", err } return result.ID, err }
go
func (c *Client) ConvertReservedIP(serverID string, ip string) (string, error) { values := url.Values{ "SUBID": {serverID}, "ip_address": {ip}, } result := IP{} err := c.post(`reservedip/convert`, values, &result) if err != nil { return "", err } return result.ID, err }
[ "func", "(", "c", "*", "Client", ")", "ConvertReservedIP", "(", "serverID", "string", ",", "ip", "string", ")", "(", "string", ",", "error", ")", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "serverID", "}", ",", "\"", "\""...
// ConvertReservedIP converts an existing virtual machines IP to a reserved IP
[ "ConvertReservedIP", "converts", "an", "existing", "virtual", "machines", "IP", "to", "a", "reserved", "IP" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L180-L192
train
JamesClonk/vultr
lib/ip.go
ListIPv4
func (c *Client) ListIPv4(id string) (list []IPv4, err error) { var ipMap map[string][]IPv4 if err := c.get(`server/list_ipv4?SUBID=`+id+`&public_network=yes`, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(ipv4s(list)) return list, nil }
go
func (c *Client) ListIPv4(id string) (list []IPv4, err error) { var ipMap map[string][]IPv4 if err := c.get(`server/list_ipv4?SUBID=`+id+`&public_network=yes`, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(ipv4s(list)) return list, nil }
[ "func", "(", "c", "*", "Client", ")", "ListIPv4", "(", "id", "string", ")", "(", "list", "[", "]", "IPv4", ",", "err", "error", ")", "{", "var", "ipMap", "map", "[", "string", "]", "[", "]", "IPv4", "\n", "if", "err", ":=", "c", ".", "get", "...
// ListIPv4 lists the IPv4 information of a virtual machine
[ "ListIPv4", "lists", "the", "IPv4", "information", "of", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L68-L81
train
JamesClonk/vultr
lib/ip.go
CreateIPv4
func (c *Client) CreateIPv4(id string, reboot bool) error { values := url.Values{ "SUBID": {id}, "reboot": {fmt.Sprintf("%t", reboot)}, } if err := c.post(`server/create_ipv4`, values, nil); err != nil { return err } return nil }
go
func (c *Client) CreateIPv4(id string, reboot bool) error { values := url.Values{ "SUBID": {id}, "reboot": {fmt.Sprintf("%t", reboot)}, } if err := c.post(`server/create_ipv4`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "CreateIPv4", "(", "id", "string", ",", "reboot", "bool", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "fmt", ".", "Sprintf", "("...
// CreateIPv4 creates an IPv4 address and attaches it to a virtual machine
[ "CreateIPv4", "creates", "an", "IPv4", "address", "and", "attaches", "it", "to", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L84-L94
train
JamesClonk/vultr
lib/ip.go
DeleteIPv4
func (c *Client) DeleteIPv4(id, ip string) error { values := url.Values{ "SUBID": {id}, "ip": {ip}, } if err := c.post(`server/destroy_ipv4`, values, nil); err != nil { return err } return nil }
go
func (c *Client) DeleteIPv4(id, ip string) error { values := url.Values{ "SUBID": {id}, "ip": {ip}, } if err := c.post(`server/destroy_ipv4`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "DeleteIPv4", "(", "id", ",", "ip", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "ip", "}", ",", "}", "\n\n", "if", ...
// DeleteIPv4 deletes an IPv4 address and detaches it from a virtual machine
[ "DeleteIPv4", "deletes", "an", "IPv4", "address", "and", "detaches", "it", "from", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L97-L107
train
JamesClonk/vultr
lib/ip.go
ListIPv6
func (c *Client) ListIPv6(id string) (list []IPv6, err error) { var ipMap map[string][]IPv6 if err := c.get(`server/list_ipv6?SUBID=`+id, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(ipv6s(list)) return list, nil }
go
func (c *Client) ListIPv6(id string) (list []IPv6, err error) { var ipMap map[string][]IPv6 if err := c.get(`server/list_ipv6?SUBID=`+id, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(ipv6s(list)) return list, nil }
[ "func", "(", "c", "*", "Client", ")", "ListIPv6", "(", "id", "string", ")", "(", "list", "[", "]", "IPv6", ",", "err", "error", ")", "{", "var", "ipMap", "map", "[", "string", "]", "[", "]", "IPv6", "\n", "if", "err", ":=", "c", ".", "get", "...
// ListIPv6 lists the IPv4 information of a virtual machine
[ "ListIPv6", "lists", "the", "IPv4", "information", "of", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L110-L123
train
JamesClonk/vultr
lib/ip.go
ListIPv6ReverseDNS
func (c *Client) ListIPv6ReverseDNS(id string) (list []ReverseDNSIPv6, err error) { var ipMap map[string][]ReverseDNSIPv6 if err := c.get(`server/reverse_list_ipv6?SUBID=`+id, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(reverseDNSIPv6s(list)) return list, nil }
go
func (c *Client) ListIPv6ReverseDNS(id string) (list []ReverseDNSIPv6, err error) { var ipMap map[string][]ReverseDNSIPv6 if err := c.get(`server/reverse_list_ipv6?SUBID=`+id, &ipMap); err != nil { return nil, err } for _, iplist := range ipMap { for _, ip := range iplist { list = append(list, ip) } } sort.Sort(reverseDNSIPv6s(list)) return list, nil }
[ "func", "(", "c", "*", "Client", ")", "ListIPv6ReverseDNS", "(", "id", "string", ")", "(", "list", "[", "]", "ReverseDNSIPv6", ",", "err", "error", ")", "{", "var", "ipMap", "map", "[", "string", "]", "[", "]", "ReverseDNSIPv6", "\n", "if", "err", ":...
// ListIPv6ReverseDNS lists the IPv6 reverse DNS entries of a virtual machine
[ "ListIPv6ReverseDNS", "lists", "the", "IPv6", "reverse", "DNS", "entries", "of", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L126-L139
train
JamesClonk/vultr
lib/bare_metal_plans.go
GetBareMetalPlans
func (c *Client) GetBareMetalPlans() ([]BareMetalPlan, error) { var bareMetalPlanMap map[string]BareMetalPlan if err := c.get(`plans/list_baremetal`, &bareMetalPlanMap); err != nil { return nil, err } var b bareMetalPlans for _, bareMetalPlan := range bareMetalPlanMap { b = append(b, bareMetalPlan) } sort.Sort(bareMetalPlans(b)) return b, nil }
go
func (c *Client) GetBareMetalPlans() ([]BareMetalPlan, error) { var bareMetalPlanMap map[string]BareMetalPlan if err := c.get(`plans/list_baremetal`, &bareMetalPlanMap); err != nil { return nil, err } var b bareMetalPlans for _, bareMetalPlan := range bareMetalPlanMap { b = append(b, bareMetalPlan) } sort.Sort(bareMetalPlans(b)) return b, nil }
[ "func", "(", "c", "*", "Client", ")", "GetBareMetalPlans", "(", ")", "(", "[", "]", "BareMetalPlan", ",", "error", ")", "{", "var", "bareMetalPlanMap", "map", "[", "string", "]", "BareMetalPlan", "\n", "if", "err", ":=", "c", ".", "get", "(", "`plans/l...
// GetBareMetalPlans returns a list of all available bare metal plans on Vultr account.
[ "GetBareMetalPlans", "returns", "a", "list", "of", "all", "available", "bare", "metal", "plans", "on", "Vultr", "account", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal_plans.go#L57-L70
train
JamesClonk/vultr
lib/bare_metal_plans.go
GetAvailableBareMetalPlansForRegion
func (c *Client) GetAvailableBareMetalPlansForRegion(id int) ([]int, error) { var bareMetalPlanIDs []int if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &bareMetalPlanIDs); err != nil { return nil, err } return bareMetalPlanIDs, nil }
go
func (c *Client) GetAvailableBareMetalPlansForRegion(id int) ([]int, error) { var bareMetalPlanIDs []int if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &bareMetalPlanIDs); err != nil { return nil, err } return bareMetalPlanIDs, nil }
[ "func", "(", "c", "*", "Client", ")", "GetAvailableBareMetalPlansForRegion", "(", "id", "int", ")", "(", "[", "]", "int", ",", "error", ")", "{", "var", "bareMetalPlanIDs", "[", "]", "int", "\n", "if", "err", ":=", "c", ".", "get", "(", "fmt", ".", ...
// GetAvailableBareMetalPlansForRegion returns available bare metal plans for specified region.
[ "GetAvailableBareMetalPlansForRegion", "returns", "available", "bare", "metal", "plans", "for", "specified", "region", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal_plans.go#L73-L79
train
JamesClonk/vultr
lib/network.go
GetNetworks
func (c *Client) GetNetworks() (nets []Network, err error) { var netMap map[string]Network if err := c.get(`network/list`, &netMap); err != nil { return nil, err } for _, net := range netMap { nets = append(nets, net) } sort.Sort(networks(nets)) return nets, nil }
go
func (c *Client) GetNetworks() (nets []Network, err error) { var netMap map[string]Network if err := c.get(`network/list`, &netMap); err != nil { return nil, err } for _, net := range netMap { nets = append(nets, net) } sort.Sort(networks(nets)) return nets, nil }
[ "func", "(", "c", "*", "Client", ")", "GetNetworks", "(", ")", "(", "nets", "[", "]", "Network", ",", "err", "error", ")", "{", "var", "netMap", "map", "[", "string", "]", "Network", "\n", "if", "err", ":=", "c", ".", "get", "(", "`network/list`", ...
// GetNetworks returns a list of Networks from Vultr account
[ "GetNetworks", "returns", "a", "list", "of", "Networks", "from", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/network.go#L36-L47
train
JamesClonk/vultr
lib/network.go
CreateNetwork
func (c *Client) CreateNetwork(regionID int, description string, subnet *net.IPNet) (Network, error) { var net string var mask int values := url.Values{ "DCID": {fmt.Sprintf("%v", regionID)}, "description": {description}, } if subnet != nil && subnet.IP.To4() != nil { net = subnet.IP.To4().String() mask, _ = subnet.Mask.Size() values.Add("v4_subnet", net) values.Add("v4_subnet_mask", fmt.Sprintf("%v", mask)) } var network Network if err := c.post(`network/create`, values, &network); err != nil { return Network{}, err } network.RegionID = regionID network.Description = description network.V4Subnet = net network.V4SubnetMask = mask return network, nil }
go
func (c *Client) CreateNetwork(regionID int, description string, subnet *net.IPNet) (Network, error) { var net string var mask int values := url.Values{ "DCID": {fmt.Sprintf("%v", regionID)}, "description": {description}, } if subnet != nil && subnet.IP.To4() != nil { net = subnet.IP.To4().String() mask, _ = subnet.Mask.Size() values.Add("v4_subnet", net) values.Add("v4_subnet_mask", fmt.Sprintf("%v", mask)) } var network Network if err := c.post(`network/create`, values, &network); err != nil { return Network{}, err } network.RegionID = regionID network.Description = description network.V4Subnet = net network.V4SubnetMask = mask return network, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateNetwork", "(", "regionID", "int", ",", "description", "string", ",", "subnet", "*", "net", ".", "IPNet", ")", "(", "Network", ",", "error", ")", "{", "var", "net", "string", "\n", "var", "mask", "int", "\n...
// CreateNetwork creates new Network on Vultr
[ "CreateNetwork", "creates", "new", "Network", "on", "Vultr" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/network.go#L50-L73
train
JamesClonk/vultr
lib/client.go
NewClient
func NewClient(apiKey string, options *Options) *Client { userAgent := "vultr-go/" + Version transport := &http.Transport{ TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper), } client := http.DefaultClient client.Transport = transport endpoint, _ := url.Parse(DefaultEndpoint) rate := 505 * time.Millisecond attempts := 1 if options != nil { if options.HTTPClient != nil { client = options.HTTPClient } if options.UserAgent != "" { userAgent = options.UserAgent } if options.Endpoint != "" { endpoint, _ = url.Parse(options.Endpoint) } if options.RateLimitation != 0 { rate = options.RateLimitation } if options.MaxRetries != 0 { attempts = options.MaxRetries + 1 } } return &Client{ UserAgent: userAgent, client: client, Endpoint: endpoint, APIKey: apiKey, MaxAttempts: attempts, bucket: ratelimit.NewBucket(rate, 1), } }
go
func NewClient(apiKey string, options *Options) *Client { userAgent := "vultr-go/" + Version transport := &http.Transport{ TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper), } client := http.DefaultClient client.Transport = transport endpoint, _ := url.Parse(DefaultEndpoint) rate := 505 * time.Millisecond attempts := 1 if options != nil { if options.HTTPClient != nil { client = options.HTTPClient } if options.UserAgent != "" { userAgent = options.UserAgent } if options.Endpoint != "" { endpoint, _ = url.Parse(options.Endpoint) } if options.RateLimitation != 0 { rate = options.RateLimitation } if options.MaxRetries != 0 { attempts = options.MaxRetries + 1 } } return &Client{ UserAgent: userAgent, client: client, Endpoint: endpoint, APIKey: apiKey, MaxAttempts: attempts, bucket: ratelimit.NewBucket(rate, 1), } }
[ "func", "NewClient", "(", "apiKey", "string", ",", "options", "*", "Options", ")", "*", "Client", "{", "userAgent", ":=", "\"", "\"", "+", "Version", "\n", "transport", ":=", "&", "http", ".", "Transport", "{", "TLSNextProto", ":", "make", "(", "map", ...
// NewClient creates new Vultr API client. Options are optional and can be nil.
[ "NewClient", "creates", "new", "Vultr", "API", "client", ".", "Options", "are", "optional", "and", "can", "be", "nil", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L86-L123
train
JamesClonk/vultr
lib/client.go
backoffDuration
func backoffDuration(retryCount int) time.Duration { // Upper limit of delay at ~1 minute if retryCount > 7 { retryCount = 7 } rand.Seed(time.Now().UnixNano()) delay := (1 << uint(retryCount)) * (rand.Intn(150) + 500) return time.Duration(delay) * time.Millisecond }
go
func backoffDuration(retryCount int) time.Duration { // Upper limit of delay at ~1 minute if retryCount > 7 { retryCount = 7 } rand.Seed(time.Now().UnixNano()) delay := (1 << uint(retryCount)) * (rand.Intn(150) + 500) return time.Duration(delay) * time.Millisecond }
[ "func", "backoffDuration", "(", "retryCount", "int", ")", "time", ".", "Duration", "{", "// Upper limit of delay at ~1 minute", "if", "retryCount", ">", "7", "{", "retryCount", "=", "7", "\n", "}", "\n\n", "rand", ".", "Seed", "(", "time", ".", "Now", "(", ...
// backoffDuration returns the duration to wait before retrying the request. // Duration is an exponential function of the retry count with a jitter of ~0-30%.
[ "backoffDuration", "returns", "the", "duration", "to", "wait", "before", "retrying", "the", "request", ".", "Duration", "is", "an", "exponential", "function", "of", "the", "retry", "count", "with", "a", "jitter", "of", "~0", "-", "30%", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L240-L249
train
JamesClonk/vultr
lib/client.go
isCodeRetryable
func isCodeRetryable(statusCode int) bool { if _, ok := retryableStatusCodes[statusCode]; ok { return true } return false }
go
func isCodeRetryable(statusCode int) bool { if _, ok := retryableStatusCodes[statusCode]; ok { return true } return false }
[ "func", "isCodeRetryable", "(", "statusCode", "int", ")", "bool", "{", "if", "_", ",", "ok", ":=", "retryableStatusCodes", "[", "statusCode", "]", ";", "ok", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// isCodeRetryable returns true if the given status code means that we should retry.
[ "isCodeRetryable", "returns", "true", "if", "the", "given", "status", "code", "means", "that", "we", "should", "retry", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L252-L258
train
JamesClonk/vultr
lib/regions.go
GetRegions
func (c *Client) GetRegions() ([]Region, error) { var regionMap map[string]Region if err := c.get(`regions/list`, &regionMap); err != nil { return nil, err } var regionList []Region for _, os := range regionMap { regionList = append(regionList, os) } sort.Sort(regions(regionList)) return regionList, nil }
go
func (c *Client) GetRegions() ([]Region, error) { var regionMap map[string]Region if err := c.get(`regions/list`, &regionMap); err != nil { return nil, err } var regionList []Region for _, os := range regionMap { regionList = append(regionList, os) } sort.Sort(regions(regionList)) return regionList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetRegions", "(", ")", "(", "[", "]", "Region", ",", "error", ")", "{", "var", "regionMap", "map", "[", "string", "]", "Region", "\n", "if", "err", ":=", "c", ".", "get", "(", "`regions/list`", ",", "&", "re...
// GetRegions returns a list of all available Vultr regions
[ "GetRegions", "returns", "a", "list", "of", "all", "available", "Vultr", "regions" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/regions.go#L32-L44
train
JamesClonk/vultr
lib/plans.go
GetPlans
func (c *Client) GetPlans() ([]Plan, error) { var planMap map[string]Plan if err := c.get(`plans/list`, &planMap); err != nil { return nil, err } var p plans for _, plan := range planMap { p = append(p, plan) } sort.Sort(plans(p)) return p, nil }
go
func (c *Client) GetPlans() ([]Plan, error) { var planMap map[string]Plan if err := c.get(`plans/list`, &planMap); err != nil { return nil, err } var p plans for _, plan := range planMap { p = append(p, plan) } sort.Sort(plans(p)) return p, nil }
[ "func", "(", "c", "*", "Client", ")", "GetPlans", "(", ")", "(", "[", "]", "Plan", ",", "error", ")", "{", "var", "planMap", "map", "[", "string", "]", "Plan", "\n", "if", "err", ":=", "c", ".", "get", "(", "`plans/list`", ",", "&", "planMap", ...
// GetPlans returns a list of all available plans on Vultr account
[ "GetPlans", "returns", "a", "list", "of", "all", "available", "plans", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/plans.go#L57-L70
train
JamesClonk/vultr
lib/plans.go
GetAvailablePlansForRegion
func (c *Client) GetAvailablePlansForRegion(id int) (planIDs []int, err error) { if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &planIDs); err != nil { return nil, err } return }
go
func (c *Client) GetAvailablePlansForRegion(id int) (planIDs []int, err error) { if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &planIDs); err != nil { return nil, err } return }
[ "func", "(", "c", "*", "Client", ")", "GetAvailablePlansForRegion", "(", "id", "int", ")", "(", "planIDs", "[", "]", "int", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "fmt", ".", "Sprintf", "(", "`regions/availability?DCID=...
// GetAvailablePlansForRegion returns available plans for specified region
[ "GetAvailablePlansForRegion", "returns", "available", "plans", "for", "specified", "region" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/plans.go#L73-L78
train
JamesClonk/vultr
lib/iso.go
GetISO
func (c *Client) GetISO() ([]ISO, error) { var isoMap map[string]ISO if err := c.get(`iso/list`, &isoMap); err != nil { return nil, err } var isoList []ISO for _, iso := range isoMap { isoList = append(isoList, iso) } sort.Sort(isos(isoList)) return isoList, nil }
go
func (c *Client) GetISO() ([]ISO, error) { var isoMap map[string]ISO if err := c.get(`iso/list`, &isoMap); err != nil { return nil, err } var isoList []ISO for _, iso := range isoMap { isoList = append(isoList, iso) } sort.Sort(isos(isoList)) return isoList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetISO", "(", ")", "(", "[", "]", "ISO", ",", "error", ")", "{", "var", "isoMap", "map", "[", "string", "]", "ISO", "\n", "if", "err", ":=", "c", ".", "get", "(", "`iso/list`", ",", "&", "isoMap", ")", "...
// GetISO returns a list of all ISO images on Vultr account
[ "GetISO", "returns", "a", "list", "of", "all", "ISO", "images", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/iso.go#L32-L44
train
JamesClonk/vultr
lib/servers.go
GetServersByTag
func (c *Client) GetServersByTag(tag string) (serverList []Server, err error) { var serverMap map[string]Server if err := c.get(`server/list?tag=`+tag, &serverMap); err != nil { return nil, err } for _, server := range serverMap { serverList = append(serverList, server) } sort.Sort(servers(serverList)) return serverList, nil }
go
func (c *Client) GetServersByTag(tag string) (serverList []Server, err error) { var serverMap map[string]Server if err := c.get(`server/list?tag=`+tag, &serverMap); err != nil { return nil, err } for _, server := range serverMap { serverList = append(serverList, server) } sort.Sort(servers(serverList)) return serverList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetServersByTag", "(", "tag", "string", ")", "(", "serverList", "[", "]", "Server", ",", "err", "error", ")", "{", "var", "serverMap", "map", "[", "string", "]", "Server", "\n", "if", "err", ":=", "c", ".", "g...
// GetServersByTag returns a list of all virtual machines matching by tag
[ "GetServersByTag", "returns", "a", "list", "of", "all", "virtual", "machines", "matching", "by", "tag" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L243-L254
train
JamesClonk/vultr
lib/servers.go
GetServer
func (c *Client) GetServer(id string) (server Server, err error) { if err := c.get(`server/list?SUBID=`+id, &server); err != nil { return Server{}, err } return server, nil }
go
func (c *Client) GetServer(id string) (server Server, err error) { if err := c.get(`server/list?SUBID=`+id, &server); err != nil { return Server{}, err } return server, nil }
[ "func", "(", "c", "*", "Client", ")", "GetServer", "(", "id", "string", ")", "(", "server", "Server", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`server/list?SUBID=`", "+", "id", ",", "&", "server", ")", ";", "err", ...
// GetServer returns the virtual machine with the given ID
[ "GetServer", "returns", "the", "virtual", "machine", "with", "the", "given", "ID" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L257-L262
train
JamesClonk/vultr
lib/servers.go
RenameServer
func (c *Client) RenameServer(id, name string) error { values := url.Values{ "SUBID": {id}, "label": {name}, } if err := c.post(`server/label_set`, values, nil); err != nil { return err } return nil }
go
func (c *Client) RenameServer(id, name string) error { values := url.Values{ "SUBID": {id}, "label": {name}, } if err := c.post(`server/label_set`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "RenameServer", "(", "id", ",", "name", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "name", "}", ",", "}", "\n\n", "...
// RenameServer renames an existing virtual machine
[ "RenameServer", "renames", "an", "existing", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L357-L367
train
JamesClonk/vultr
lib/servers.go
TagServer
func (c *Client) TagServer(id, tag string) error { values := url.Values{ "SUBID": {id}, "tag": {tag}, } if err := c.post(`server/tag_set`, values, nil); err != nil { return err } return nil }
go
func (c *Client) TagServer(id, tag string) error { values := url.Values{ "SUBID": {id}, "tag": {tag}, } if err := c.post(`server/tag_set`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "TagServer", "(", "id", ",", "tag", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "tag", "}", ",", "}", "\n\n", "if", ...
// TagServer replaces the tag on an existing virtual machine
[ "TagServer", "replaces", "the", "tag", "on", "an", "existing", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L370-L380
train
JamesClonk/vultr
lib/servers.go
StartServer
func (c *Client) StartServer(id string) error { values := url.Values{ "SUBID": {id}, } if err := c.post(`server/start`, values, nil); err != nil { return err } return nil }
go
func (c *Client) StartServer(id string) error { values := url.Values{ "SUBID": {id}, } if err := c.post(`server/start`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "StartServer", "(", "id", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "}", "\n\n", "if", "err", ":=", "c", ".", "post", "(", "`server/start`",...
// StartServer starts an existing virtual machine
[ "StartServer", "starts", "an", "existing", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L383-L392
train
JamesClonk/vultr
lib/servers.go
ChangeOSofServer
func (c *Client) ChangeOSofServer(id string, osID int) error { values := url.Values{ "SUBID": {id}, "OSID": {fmt.Sprintf("%v", osID)}, } if err := c.post(`server/os_change`, values, nil); err != nil { return err } return nil }
go
func (c *Client) ChangeOSofServer(id string, osID int) error { values := url.Values{ "SUBID": {id}, "OSID": {fmt.Sprintf("%v", osID)}, } if err := c.post(`server/os_change`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "ChangeOSofServer", "(", "id", "string", ",", "osID", "int", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "fmt", ".", "Sprintf", ...
// ChangeOSofServer changes the virtual machine to a different operating system
[ "ChangeOSofServer", "changes", "the", "virtual", "machine", "to", "a", "different", "operating", "system" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L431-L441
train
JamesClonk/vultr
lib/servers.go
AttachISOtoServer
func (c *Client) AttachISOtoServer(id string, isoID int) error { values := url.Values{ "SUBID": {id}, "ISOID": {fmt.Sprintf("%v", isoID)}, } if err := c.post(`server/iso_attach`, values, nil); err != nil { return err } return nil }
go
func (c *Client) AttachISOtoServer(id string, isoID int) error { values := url.Values{ "SUBID": {id}, "ISOID": {fmt.Sprintf("%v", isoID)}, } if err := c.post(`server/iso_attach`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "AttachISOtoServer", "(", "id", "string", ",", "isoID", "int", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "fmt", ".", "Sprintf", ...
// AttachISOtoServer attaches an ISO image to an existing virtual machine and reboots it
[ "AttachISOtoServer", "attaches", "an", "ISO", "image", "to", "an", "existing", "virtual", "machine", "and", "reboots", "it" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L458-L468
train
JamesClonk/vultr
lib/servers.go
GetISOStatusofServer
func (c *Client) GetISOStatusofServer(id string) (isoStatus ISOStatus, err error) { if err := c.get(`server/iso_status?SUBID=`+id, &isoStatus); err != nil { return ISOStatus{}, err } return isoStatus, nil }
go
func (c *Client) GetISOStatusofServer(id string) (isoStatus ISOStatus, err error) { if err := c.get(`server/iso_status?SUBID=`+id, &isoStatus); err != nil { return ISOStatus{}, err } return isoStatus, nil }
[ "func", "(", "c", "*", "Client", ")", "GetISOStatusofServer", "(", "id", "string", ")", "(", "isoStatus", "ISOStatus", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`server/iso_status?SUBID=`", "+", "id", ",", "&", "isoStatus",...
// GetISOStatusofServer retrieves the current ISO image state of an existing virtual machine
[ "GetISOStatusofServer", "retrieves", "the", "current", "ISO", "image", "state", "of", "an", "existing", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L483-L488
train
JamesClonk/vultr
lib/servers.go
RestoreBackup
func (c *Client) RestoreBackup(id, backupID string) error { values := url.Values{ "SUBID": {id}, "BACKUPID": {backupID}, } if err := c.post(`server/restore_backup`, values, nil); err != nil { return err } return nil }
go
func (c *Client) RestoreBackup(id, backupID string) error { values := url.Values{ "SUBID": {id}, "BACKUPID": {backupID}, } if err := c.post(`server/restore_backup`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "RestoreBackup", "(", "id", ",", "backupID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "backupID", "}", ",", "}", "\...
// RestoreBackup restore the specified backup to the virtual machine
[ "RestoreBackup", "restore", "the", "specified", "backup", "to", "the", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L491-L501
train
JamesClonk/vultr
lib/servers.go
RestoreSnapshot
func (c *Client) RestoreSnapshot(id, snapshotID string) error { values := url.Values{ "SUBID": {id}, "SNAPSHOTID": {snapshotID}, } if err := c.post(`server/restore_snapshot`, values, nil); err != nil { return err } return nil }
go
func (c *Client) RestoreSnapshot(id, snapshotID string) error { values := url.Values{ "SUBID": {id}, "SNAPSHOTID": {snapshotID}, } if err := c.post(`server/restore_snapshot`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "RestoreSnapshot", "(", "id", ",", "snapshotID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "snapshotID", "}", ",", "}"...
// RestoreSnapshot restore the specified snapshot to the virtual machine
[ "RestoreSnapshot", "restore", "the", "specified", "snapshot", "to", "the", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L504-L514
train
JamesClonk/vultr
lib/servers.go
SetFirewallGroup
func (c *Client) SetFirewallGroup(id, firewallgroup string) error { values := url.Values{ "SUBID": {id}, "FIREWALLGROUPID": {firewallgroup}, } if err := c.post(`server/firewall_group_set`, values, nil); err != nil { return err } return nil }
go
func (c *Client) SetFirewallGroup(id, firewallgroup string) error { values := url.Values{ "SUBID": {id}, "FIREWALLGROUPID": {firewallgroup}, } if err := c.post(`server/firewall_group_set`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "SetFirewallGroup", "(", "id", ",", "firewallgroup", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "firewallgroup", "}", ","...
// SetFirewallGroup adds a virtual machine to a firewall group
[ "SetFirewallGroup", "adds", "a", "virtual", "machine", "to", "a", "firewall", "group" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L529-L539
train
JamesClonk/vultr
lib/servers.go
BandwidthOfServer
func (c *Client) BandwidthOfServer(id string) (bandwidth []map[string]string, err error) { var bandwidthMap map[string][][]string if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil { return nil, err } // parse incoming bytes for _, b := range bandwidthMap["incoming_bytes"] { bMap := make(map[string]string) bMap["date"] = b[0] bMap["incoming"] = b[1] bandwidth = append(bandwidth, bMap) } // parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match) for _, b := range bandwidthMap["outgoing_bytes"] { for i := range bandwidth { if bandwidth[i]["date"] == b[0] { bandwidth[i]["outgoing"] = b[1] break } } } return bandwidth, nil }
go
func (c *Client) BandwidthOfServer(id string) (bandwidth []map[string]string, err error) { var bandwidthMap map[string][][]string if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil { return nil, err } // parse incoming bytes for _, b := range bandwidthMap["incoming_bytes"] { bMap := make(map[string]string) bMap["date"] = b[0] bMap["incoming"] = b[1] bandwidth = append(bandwidth, bMap) } // parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match) for _, b := range bandwidthMap["outgoing_bytes"] { for i := range bandwidth { if bandwidth[i]["date"] == b[0] { bandwidth[i]["outgoing"] = b[1] break } } } return bandwidth, nil }
[ "func", "(", "c", "*", "Client", ")", "BandwidthOfServer", "(", "id", "string", ")", "(", "bandwidth", "[", "]", "map", "[", "string", "]", "string", ",", "err", "error", ")", "{", "var", "bandwidthMap", "map", "[", "string", "]", "[", "]", "[", "]...
// BandwidthOfServer retrieves the bandwidth used by a virtual machine
[ "BandwidthOfServer", "retrieves", "the", "bandwidth", "used", "by", "a", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L547-L572
train
JamesClonk/vultr
lib/servers.go
ChangeApplicationofServer
func (c *Client) ChangeApplicationofServer(id string, appID string) error { values := url.Values{ "SUBID": {id}, "APPID": {appID}, } if err := c.post(`server/app_change`, values, nil); err != nil { return err } return nil }
go
func (c *Client) ChangeApplicationofServer(id string, appID string) error { values := url.Values{ "SUBID": {id}, "APPID": {appID}, } if err := c.post(`server/app_change`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "ChangeApplicationofServer", "(", "id", "string", ",", "appID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "appID", "}", ...
// ChangeApplicationofServer changes the virtual machine to a different application
[ "ChangeApplicationofServer", "changes", "the", "virtual", "machine", "to", "a", "different", "application" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L575-L585
train
JamesClonk/vultr
lib/servers.go
ListApplicationsforServer
func (c *Client) ListApplicationsforServer(id string) (apps []Application, err error) { var appMap map[string]Application if err := c.get(`server/app_change_list?SUBID=`+id, &appMap); err != nil { return nil, err } for _, app := range appMap { apps = append(apps, app) } sort.Sort(applications(apps)) return apps, nil }
go
func (c *Client) ListApplicationsforServer(id string) (apps []Application, err error) { var appMap map[string]Application if err := c.get(`server/app_change_list?SUBID=`+id, &appMap); err != nil { return nil, err } for _, app := range appMap { apps = append(apps, app) } sort.Sort(applications(apps)) return apps, nil }
[ "func", "(", "c", "*", "Client", ")", "ListApplicationsforServer", "(", "id", "string", ")", "(", "apps", "[", "]", "Application", ",", "err", "error", ")", "{", "var", "appMap", "map", "[", "string", "]", "Application", "\n", "if", "err", ":=", "c", ...
// ListApplicationsforServer lists all available operating systems to which an existing virtual machine can be changed
[ "ListApplicationsforServer", "lists", "all", "available", "operating", "systems", "to", "which", "an", "existing", "virtual", "machine", "can", "be", "changed" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L588-L599
train
JamesClonk/vultr
lib/servers.go
GetApplicationInfo
func (c *Client) GetApplicationInfo(id string) (appInfo AppInfo, err error) { if err := c.get(`server/get_app_info?SUBID=`+id, &appInfo); err != nil { return AppInfo{}, err } return appInfo, nil }
go
func (c *Client) GetApplicationInfo(id string) (appInfo AppInfo, err error) { if err := c.get(`server/get_app_info?SUBID=`+id, &appInfo); err != nil { return AppInfo{}, err } return appInfo, nil }
[ "func", "(", "c", "*", "Client", ")", "GetApplicationInfo", "(", "id", "string", ")", "(", "appInfo", "AppInfo", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`server/get_app_info?SUBID=`", "+", "id", ",", "&", "appInfo", ")"...
// GetApplicationInfo retrieves the application information for the existing virtual machine
[ "GetApplicationInfo", "retrieves", "the", "application", "information", "for", "the", "existing", "virtual", "machine" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L602-L607
train
JamesClonk/vultr
lib/servers.go
ListPrivateNetworksForServer
func (c *Client) ListPrivateNetworksForServer(id string) (nets []PrivateNetwork, err error) { var netMap map[string]PrivateNetwork if err := c.get(`server/private_networks?SUBID=`+id, &netMap); err != nil { return nil, err } for _, net := range netMap { nets = append(nets, net) } sort.Sort(privateNetworks(nets)) return nets, nil }
go
func (c *Client) ListPrivateNetworksForServer(id string) (nets []PrivateNetwork, err error) { var netMap map[string]PrivateNetwork if err := c.get(`server/private_networks?SUBID=`+id, &netMap); err != nil { return nil, err } for _, net := range netMap { nets = append(nets, net) } sort.Sort(privateNetworks(nets)) return nets, nil }
[ "func", "(", "c", "*", "Client", ")", "ListPrivateNetworksForServer", "(", "id", "string", ")", "(", "nets", "[", "]", "PrivateNetwork", ",", "err", "error", ")", "{", "var", "netMap", "map", "[", "string", "]", "PrivateNetwork", "\n", "if", "err", ":=",...
// ListPrivateNetworksForServer lists all the private networks to which an existing virtual machine is attached
[ "ListPrivateNetworksForServer", "lists", "all", "the", "private", "networks", "to", "which", "an", "existing", "virtual", "machine", "is", "attached" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L625-L636
train
JamesClonk/vultr
lib/servers.go
DisablePrivateNetworkForServer
func (c *Client) DisablePrivateNetworkForServer(id, networkID string) error { values := url.Values{ "SUBID": {id}, "NETWORKID": {networkID}, } return c.post(`server/private_network_disable`, values, nil) }
go
func (c *Client) DisablePrivateNetworkForServer(id, networkID string) error { values := url.Values{ "SUBID": {id}, "NETWORKID": {networkID}, } return c.post(`server/private_network_disable`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "DisablePrivateNetworkForServer", "(", "id", ",", "networkID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "networkID", "}",...
// DisablePrivateNetworkForServer removes the given virtual machine from the given private network
[ "DisablePrivateNetworkForServer", "removes", "the", "given", "virtual", "machine", "from", "the", "given", "private", "network" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L639-L646
train
JamesClonk/vultr
lib/servers.go
EnablePrivateNetworkForServer
func (c *Client) EnablePrivateNetworkForServer(id, networkID string) error { values := url.Values{ "SUBID": {id}, } if networkID != "" { values.Add("NETWORKID", networkID) } return c.post(`server/private_network_enable`, values, nil) }
go
func (c *Client) EnablePrivateNetworkForServer(id, networkID string) error { values := url.Values{ "SUBID": {id}, } if networkID != "" { values.Add("NETWORKID", networkID) } return c.post(`server/private_network_enable`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "EnablePrivateNetworkForServer", "(", "id", ",", "networkID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "}", "\n", "if", "networkID", "!=", "\""...
// EnablePrivateNetworkForServer enables private networking for the given virtual machine. // If private networking is already enabled, then nothing occurs. // If multiple private networks exist in the virtual machine's region, then the network ID must be specified.
[ "EnablePrivateNetworkForServer", "enables", "private", "networking", "for", "the", "given", "virtual", "machine", ".", "If", "private", "networking", "is", "already", "enabled", "then", "nothing", "occurs", ".", "If", "multiple", "private", "networks", "exist", "in"...
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L651-L660
train
JamesClonk/vultr
lib/servers.go
BackupGetSchedule
func (c *Client) BackupGetSchedule(id string) (*BackupScheduleResponse, error) { var bsr = &BackupScheduleResponse{} values := url.Values{ "SUBID": {id}, } if err := c.post(`server/backup_get_schedule`, values, &bsr); err != nil { return nil, err } return bsr, nil }
go
func (c *Client) BackupGetSchedule(id string) (*BackupScheduleResponse, error) { var bsr = &BackupScheduleResponse{} values := url.Values{ "SUBID": {id}, } if err := c.post(`server/backup_get_schedule`, values, &bsr); err != nil { return nil, err } return bsr, nil }
[ "func", "(", "c", "*", "Client", ")", "BackupGetSchedule", "(", "id", "string", ")", "(", "*", "BackupScheduleResponse", ",", "error", ")", "{", "var", "bsr", "=", "&", "BackupScheduleResponse", "{", "}", "\n", "values", ":=", "url", ".", "Values", "{", ...
// BackupGetSchedule returns a virtual machines backup schedule
[ "BackupGetSchedule", "returns", "a", "virtual", "machines", "backup", "schedule" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L679-L688
train
JamesClonk/vultr
lib/servers.go
BackupSetSchedule
func (c *Client) BackupSetSchedule(id string, bs BackupSchedule) error { values := url.Values{ "SUBID": {id}, "cron_type": {bs.CronType}, "hour": {string(bs.Hour)}, "dow": {string(bs.Dow)}, "dom": {string(bs.Dom)}, } return c.post(`server/backup_set_schedule`, values, nil) }
go
func (c *Client) BackupSetSchedule(id string, bs BackupSchedule) error { values := url.Values{ "SUBID": {id}, "cron_type": {bs.CronType}, "hour": {string(bs.Hour)}, "dow": {string(bs.Dow)}, "dom": {string(bs.Dom)}, } return c.post(`server/backup_set_schedule`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "BackupSetSchedule", "(", "id", "string", ",", "bs", "BackupSchedule", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "bs", ".", "Cro...
// BackupSetSchedule sets the backup schedule given a BackupSchedule struct
[ "BackupSetSchedule", "sets", "the", "backup", "schedule", "given", "a", "BackupSchedule", "struct" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L691-L700
train
JamesClonk/vultr
lib/servers.go
ChangePlanOfServer
func (c *Client) ChangePlanOfServer(id string, planID int) error { values := url.Values{ "SUBID": {id}, "VPSPLANID": {fmt.Sprintf("%v", planID)}, } if err := c.post(`server/upgrade_plan`, values, nil); err != nil { return err } return nil }
go
func (c *Client) ChangePlanOfServer(id string, planID int) error { values := url.Values{ "SUBID": {id}, "VPSPLANID": {fmt.Sprintf("%v", planID)}, } if err := c.post(`server/upgrade_plan`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "ChangePlanOfServer", "(", "id", "string", ",", "planID", "int", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "fmt", ".", "Sprintf"...
// ChangePlanOfServer changes the virtual machine to a different plan
[ "ChangePlanOfServer", "changes", "the", "virtual", "machine", "to", "a", "different", "plan" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L703-L713
train
JamesClonk/vultr
lib/servers.go
ListUpgradePlansForServer
func (c *Client) ListUpgradePlansForServer(id string) (planIDs []int, err error) { if err := c.get(`server/upgrade_plan_list?SUBID=`+id, &planIDs); err != nil { return nil, err } return }
go
func (c *Client) ListUpgradePlansForServer(id string) (planIDs []int, err error) { if err := c.get(`server/upgrade_plan_list?SUBID=`+id, &planIDs); err != nil { return nil, err } return }
[ "func", "(", "c", "*", "Client", ")", "ListUpgradePlansForServer", "(", "id", "string", ")", "(", "planIDs", "[", "]", "int", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`server/upgrade_plan_list?SUBID=`", "+", "id", ",", "...
// ListUpgradePlansForServer retrieves a list of the VPSPLANIDs for which a virtual machine can be upgraded. // An empty response means that there are currently no upgrades available
[ "ListUpgradePlansForServer", "retrieves", "a", "list", "of", "the", "VPSPLANIDs", "for", "which", "a", "virtual", "machine", "can", "be", "upgraded", ".", "An", "empty", "response", "means", "that", "there", "are", "currently", "no", "upgrades", "available" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L717-L722
train
JamesClonk/vultr
lib/firewall.go
UnmarshalJSON
func (r *FirewallRule) UnmarshalJSON(data []byte) (err error) { if r == nil { *r = FirewallRule{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["rulenumber"]) if len(value) == 0 || value == "<nil>" { value = "0" } number, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } r.RuleNumber = int(number) value = fmt.Sprintf("%v", fields["subnet_size"]) if len(value) == 0 || value == "<nil>" { value = "0" } subnetSize, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } r.Action = fmt.Sprintf("%v", fields["action"]) r.Protocol = fmt.Sprintf("%v", fields["protocol"]) r.Port = fmt.Sprintf("%v", fields["port"]) r.Notes = fmt.Sprintf("%v", fields["notes"]) subnet := fmt.Sprintf("%v", fields["subnet"]) if subnet == "<nil>" { subnet = "" } if len(subnet) > 0 { _, r.Network, err = net.ParseCIDR(fmt.Sprintf("%s/%d", subnet, subnetSize)) if err != nil { return fmt.Errorf("Failed to parse subnet from Vultr API") } } else { // This case is used to create a valid default CIDR when the Vultr API does not return a subnet/subnet size at all, e.g. the response after creating a new rule. _, r.Network, _ = net.ParseCIDR("0.0.0.0/0") } return }
go
func (r *FirewallRule) UnmarshalJSON(data []byte) (err error) { if r == nil { *r = FirewallRule{} } var fields map[string]interface{} if err := json.Unmarshal(data, &fields); err != nil { return err } value := fmt.Sprintf("%v", fields["rulenumber"]) if len(value) == 0 || value == "<nil>" { value = "0" } number, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } r.RuleNumber = int(number) value = fmt.Sprintf("%v", fields["subnet_size"]) if len(value) == 0 || value == "<nil>" { value = "0" } subnetSize, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } r.Action = fmt.Sprintf("%v", fields["action"]) r.Protocol = fmt.Sprintf("%v", fields["protocol"]) r.Port = fmt.Sprintf("%v", fields["port"]) r.Notes = fmt.Sprintf("%v", fields["notes"]) subnet := fmt.Sprintf("%v", fields["subnet"]) if subnet == "<nil>" { subnet = "" } if len(subnet) > 0 { _, r.Network, err = net.ParseCIDR(fmt.Sprintf("%s/%d", subnet, subnetSize)) if err != nil { return fmt.Errorf("Failed to parse subnet from Vultr API") } } else { // This case is used to create a valid default CIDR when the Vultr API does not return a subnet/subnet size at all, e.g. the response after creating a new rule. _, r.Network, _ = net.ParseCIDR("0.0.0.0/0") } return }
[ "func", "(", "r", "*", "FirewallRule", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "if", "r", "==", "nil", "{", "*", "r", "=", "FirewallRule", "{", "}", "\n", "}", "\n\n", "var", "fields", "map", "[", ...
// UnmarshalJSON implements json.Unmarshaller on FirewallRule. // This is needed because the Vultr API is inconsistent in it's JSON responses. // Some fields can change type, from JSON number to JSON string and vice-versa.
[ "UnmarshalJSON", "implements", "json", ".", "Unmarshaller", "on", "FirewallRule", ".", "This", "is", "needed", "because", "the", "Vultr", "API", "is", "inconsistent", "in", "it", "s", "JSON", "responses", ".", "Some", "fields", "can", "change", "type", "from",...
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L55-L104
train
JamesClonk/vultr
lib/firewall.go
GetFirewallGroups
func (c *Client) GetFirewallGroups() ([]FirewallGroup, error) { var groupMap map[string]FirewallGroup if err := c.get(`firewall/group_list`, &groupMap); err != nil { return nil, err } var groupList []FirewallGroup for _, g := range groupMap { groupList = append(groupList, g) } sort.Sort(firewallGroups(groupList)) return groupList, nil }
go
func (c *Client) GetFirewallGroups() ([]FirewallGroup, error) { var groupMap map[string]FirewallGroup if err := c.get(`firewall/group_list`, &groupMap); err != nil { return nil, err } var groupList []FirewallGroup for _, g := range groupMap { groupList = append(groupList, g) } sort.Sort(firewallGroups(groupList)) return groupList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetFirewallGroups", "(", ")", "(", "[", "]", "FirewallGroup", ",", "error", ")", "{", "var", "groupMap", "map", "[", "string", "]", "FirewallGroup", "\n", "if", "err", ":=", "c", ".", "get", "(", "`firewall/group_...
// GetFirewallGroups returns a list of all available firewall groups on Vultr
[ "GetFirewallGroups", "returns", "a", "list", "of", "all", "available", "firewall", "groups", "on", "Vultr" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L107-L119
train
JamesClonk/vultr
lib/firewall.go
GetFirewallGroup
func (c *Client) GetFirewallGroup(id string) (FirewallGroup, error) { groups, err := c.GetFirewallGroups() if err != nil { return FirewallGroup{}, err } for _, g := range groups { if g.ID == id { return g, nil } } return FirewallGroup{}, fmt.Errorf("Firewall group with ID %v not found", id) }
go
func (c *Client) GetFirewallGroup(id string) (FirewallGroup, error) { groups, err := c.GetFirewallGroups() if err != nil { return FirewallGroup{}, err } for _, g := range groups { if g.ID == id { return g, nil } } return FirewallGroup{}, fmt.Errorf("Firewall group with ID %v not found", id) }
[ "func", "(", "c", "*", "Client", ")", "GetFirewallGroup", "(", "id", "string", ")", "(", "FirewallGroup", ",", "error", ")", "{", "groups", ",", "err", ":=", "c", ".", "GetFirewallGroups", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Fir...
// GetFirewallGroup returns the firewall group with given ID
[ "GetFirewallGroup", "returns", "the", "firewall", "group", "with", "given", "ID" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L122-L134
train
JamesClonk/vultr
lib/firewall.go
CreateFirewallGroup
func (c *Client) CreateFirewallGroup(description string) (string, error) { values := url.Values{} // Optional description if len(description) > 0 { values.Add("description", description) } var result FirewallGroup err := c.post(`firewall/group_create`, values, &result) if err != nil { return "", err } return result.ID, nil }
go
func (c *Client) CreateFirewallGroup(description string) (string, error) { values := url.Values{} // Optional description if len(description) > 0 { values.Add("description", description) } var result FirewallGroup err := c.post(`firewall/group_create`, values, &result) if err != nil { return "", err } return result.ID, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateFirewallGroup", "(", "description", "string", ")", "(", "string", ",", "error", ")", "{", "values", ":=", "url", ".", "Values", "{", "}", "\n\n", "// Optional description", "if", "len", "(", "description", ")", ...
// CreateFirewallGroup creates a new firewall group in Vultr account
[ "CreateFirewallGroup", "creates", "a", "new", "firewall", "group", "in", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L137-L151
train
JamesClonk/vultr
lib/firewall.go
DeleteFirewallGroup
func (c *Client) DeleteFirewallGroup(groupID string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, } if err := c.post(`firewall/group_delete`, values, nil); err != nil { return err } return nil }
go
func (c *Client) DeleteFirewallGroup(groupID string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, } if err := c.post(`firewall/group_delete`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "DeleteFirewallGroup", "(", "groupID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "groupID", "}", ",", "}", "\n\n", "if", "err", ":=", "c", ".", "post", "(", ...
// DeleteFirewallGroup deletes an existing firewall group
[ "DeleteFirewallGroup", "deletes", "an", "existing", "firewall", "group" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L154-L163
train
JamesClonk/vultr
lib/firewall.go
SetFirewallGroupDescription
func (c *Client) SetFirewallGroupDescription(groupID, description string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, "description": {description}, } if err := c.post(`firewall/group_set_description`, values, nil); err != nil { return err } return nil }
go
func (c *Client) SetFirewallGroupDescription(groupID, description string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, "description": {description}, } if err := c.post(`firewall/group_set_description`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "SetFirewallGroupDescription", "(", "groupID", ",", "description", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "groupID", "}", ",", "\"", "\"", ":", "{", "descripti...
// SetFirewallGroupDescription sets the description of an existing firewall group
[ "SetFirewallGroupDescription", "sets", "the", "description", "of", "an", "existing", "firewall", "group" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L166-L176
train
JamesClonk/vultr
lib/firewall.go
GetFirewallRules
func (c *Client) GetFirewallRules(groupID string) ([]FirewallRule, error) { var ruleMap map[string]FirewallRule ipTypes := []string{"v4", "v6"} for _, ipType := range ipTypes { args := fmt.Sprintf("direction=in&FIREWALLGROUPID=%s&ip_type=%s", groupID, ipType) if err := c.get(`firewall/rule_list?`+args, &ruleMap); err != nil { return nil, err } } var ruleList []FirewallRule for _, r := range ruleMap { ruleList = append(ruleList, r) } sort.Sort(firewallRules(ruleList)) return ruleList, nil }
go
func (c *Client) GetFirewallRules(groupID string) ([]FirewallRule, error) { var ruleMap map[string]FirewallRule ipTypes := []string{"v4", "v6"} for _, ipType := range ipTypes { args := fmt.Sprintf("direction=in&FIREWALLGROUPID=%s&ip_type=%s", groupID, ipType) if err := c.get(`firewall/rule_list?`+args, &ruleMap); err != nil { return nil, err } } var ruleList []FirewallRule for _, r := range ruleMap { ruleList = append(ruleList, r) } sort.Sort(firewallRules(ruleList)) return ruleList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetFirewallRules", "(", "groupID", "string", ")", "(", "[", "]", "FirewallRule", ",", "error", ")", "{", "var", "ruleMap", "map", "[", "string", "]", "FirewallRule", "\n", "ipTypes", ":=", "[", "]", "string", "{",...
// GetFirewallRules returns a list of rules for the given firewall group
[ "GetFirewallRules", "returns", "a", "list", "of", "rules", "for", "the", "given", "firewall", "group" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L179-L196
train
JamesClonk/vultr
lib/firewall.go
DeleteFirewallRule
func (c *Client) DeleteFirewallRule(ruleNumber int, groupID string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, "rulenumber": {fmt.Sprintf("%v", ruleNumber)}, } if err := c.post(`firewall/rule_delete`, values, nil); err != nil { return err } return nil }
go
func (c *Client) DeleteFirewallRule(ruleNumber int, groupID string) error { values := url.Values{ "FIREWALLGROUPID": {groupID}, "rulenumber": {fmt.Sprintf("%v", ruleNumber)}, } if err := c.post(`firewall/rule_delete`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "DeleteFirewallRule", "(", "ruleNumber", "int", ",", "groupID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "groupID", "}", ",", "\"", "\"", ":", "{", "fmt", "....
// DeleteFirewallRule deletes an existing firewall rule
[ "DeleteFirewallRule", "deletes", "an", "existing", "firewall", "rule" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L248-L258
train
JamesClonk/vultr
lib/applications.go
GetApplications
func (c *Client) GetApplications() ([]Application, error) { var appMap map[string]Application if err := c.get(`app/list`, &appMap); err != nil { return nil, err } var appList []Application for _, app := range appMap { appList = append(appList, app) } sort.Sort(applications(appList)) return appList, nil }
go
func (c *Client) GetApplications() ([]Application, error) { var appMap map[string]Application if err := c.get(`app/list`, &appMap); err != nil { return nil, err } var appList []Application for _, app := range appMap { appList = append(appList, app) } sort.Sort(applications(appList)) return appList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetApplications", "(", ")", "(", "[", "]", "Application", ",", "error", ")", "{", "var", "appMap", "map", "[", "string", "]", "Application", "\n", "if", "err", ":=", "c", ".", "get", "(", "`app/list`", ",", "&...
// GetApplications returns a list of all available applications on Vultr
[ "GetApplications", "returns", "a", "list", "of", "all", "available", "applications", "on", "Vultr" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/applications.go#L26-L38
train
JamesClonk/vultr
lib/bare_metal.go
GetBareMetalServers
func (c *Client) GetBareMetalServers() ([]BareMetalServer, error) { var bareMetalServerMap map[string]BareMetalServer if err := c.get(`baremetal/list`, &bareMetalServerMap); err != nil { return nil, err } var bareMetalServerList []BareMetalServer for _, bareMetalServer := range bareMetalServerMap { bareMetalServerList = append(bareMetalServerList, bareMetalServer) } sort.Sort(bareMetalServers(bareMetalServerList)) return bareMetalServerList, nil }
go
func (c *Client) GetBareMetalServers() ([]BareMetalServer, error) { var bareMetalServerMap map[string]BareMetalServer if err := c.get(`baremetal/list`, &bareMetalServerMap); err != nil { return nil, err } var bareMetalServerList []BareMetalServer for _, bareMetalServer := range bareMetalServerMap { bareMetalServerList = append(bareMetalServerList, bareMetalServer) } sort.Sort(bareMetalServers(bareMetalServerList)) return bareMetalServerList, nil }
[ "func", "(", "c", "*", "Client", ")", "GetBareMetalServers", "(", ")", "(", "[", "]", "BareMetalServer", ",", "error", ")", "{", "var", "bareMetalServerMap", "map", "[", "string", "]", "BareMetalServer", "\n", "if", "err", ":=", "c", ".", "get", "(", "...
// GetBareMetalServers returns a list of current bare metal servers on the Vultr account.
[ "GetBareMetalServers", "returns", "a", "list", "of", "current", "bare", "metal", "servers", "on", "the", "Vultr", "account", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L153-L165
train
JamesClonk/vultr
lib/bare_metal.go
GetBareMetalServer
func (c *Client) GetBareMetalServer(id string) (BareMetalServer, error) { var b BareMetalServer if err := c.get(`baremetal/list?SUBID=`+id, &b); err != nil { return BareMetalServer{}, err } return b, nil }
go
func (c *Client) GetBareMetalServer(id string) (BareMetalServer, error) { var b BareMetalServer if err := c.get(`baremetal/list?SUBID=`+id, &b); err != nil { return BareMetalServer{}, err } return b, nil }
[ "func", "(", "c", "*", "Client", ")", "GetBareMetalServer", "(", "id", "string", ")", "(", "BareMetalServer", ",", "error", ")", "{", "var", "b", "BareMetalServer", "\n", "if", "err", ":=", "c", ".", "get", "(", "`baremetal/list?SUBID=`", "+", "id", ",",...
// GetBareMetalServer returns the bare metal server with the given ID.
[ "GetBareMetalServer", "returns", "the", "bare", "metal", "server", "with", "the", "given", "ID", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L183-L189
train
JamesClonk/vultr
lib/bare_metal.go
CreateBareMetalServer
func (c *Client) CreateBareMetalServer(name string, regionID, planID, osID int, options *BareMetalServerOptions) (BareMetalServer, error) { values := url.Values{ "label": {name}, "DCID": {fmt.Sprintf("%v", regionID)}, "METALPLANID": {fmt.Sprintf("%v", planID)}, "OSID": {fmt.Sprintf("%v", osID)}, } if options != nil { if options.Script != 0 { values.Add("SCRIPTID", fmt.Sprintf("%v", options.Script)) } if options.UserData != "" { values.Add("userdata", base64.StdEncoding.EncodeToString([]byte(options.UserData))) } if options.Snapshot != "" { values.Add("SNAPSHOTID", options.Snapshot) } if options.SSHKey != "" { values.Add("SSHKEYID", options.SSHKey) } values.Add("enable_ipv6", "no") if options.IPV6 { values.Set("enable_ipv6", "yes") } values.Add("notify_activate", "yes") if options.DontNotifyOnActivate { values.Set("notify_activate", "no") } if options.Hostname != "" { values.Add("hostname", options.Hostname) } if options.Tag != "" { values.Add("tag", options.Tag) } if options.AppID != "" { values.Add("APPID", options.AppID) } } var b BareMetalServer if err := c.post(`baremetal/create`, values, &b); err != nil { return BareMetalServer{}, err } b.Name = name b.RegionID = regionID b.PlanID = planID return b, nil }
go
func (c *Client) CreateBareMetalServer(name string, regionID, planID, osID int, options *BareMetalServerOptions) (BareMetalServer, error) { values := url.Values{ "label": {name}, "DCID": {fmt.Sprintf("%v", regionID)}, "METALPLANID": {fmt.Sprintf("%v", planID)}, "OSID": {fmt.Sprintf("%v", osID)}, } if options != nil { if options.Script != 0 { values.Add("SCRIPTID", fmt.Sprintf("%v", options.Script)) } if options.UserData != "" { values.Add("userdata", base64.StdEncoding.EncodeToString([]byte(options.UserData))) } if options.Snapshot != "" { values.Add("SNAPSHOTID", options.Snapshot) } if options.SSHKey != "" { values.Add("SSHKEYID", options.SSHKey) } values.Add("enable_ipv6", "no") if options.IPV6 { values.Set("enable_ipv6", "yes") } values.Add("notify_activate", "yes") if options.DontNotifyOnActivate { values.Set("notify_activate", "no") } if options.Hostname != "" { values.Add("hostname", options.Hostname) } if options.Tag != "" { values.Add("tag", options.Tag) } if options.AppID != "" { values.Add("APPID", options.AppID) } } var b BareMetalServer if err := c.post(`baremetal/create`, values, &b); err != nil { return BareMetalServer{}, err } b.Name = name b.RegionID = regionID b.PlanID = planID return b, nil }
[ "func", "(", "c", "*", "Client", ")", "CreateBareMetalServer", "(", "name", "string", ",", "regionID", ",", "planID", ",", "osID", "int", ",", "options", "*", "BareMetalServerOptions", ")", "(", "BareMetalServer", ",", "error", ")", "{", "values", ":=", "u...
// CreateBareMetalServer creates a new bare metal server on Vultr. BareMetalServerOptions are optional settings.
[ "CreateBareMetalServer", "creates", "a", "new", "bare", "metal", "server", "on", "Vultr", ".", "BareMetalServerOptions", "are", "optional", "settings", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L192-L249
train
JamesClonk/vultr
lib/bare_metal.go
RenameBareMetalServer
func (c *Client) RenameBareMetalServer(id, name string) error { values := url.Values{ "SUBID": {id}, "label": {name}, } return c.post(`baremetal/label_set`, values, nil) }
go
func (c *Client) RenameBareMetalServer(id, name string) error { values := url.Values{ "SUBID": {id}, "label": {name}, } return c.post(`baremetal/label_set`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "RenameBareMetalServer", "(", "id", ",", "name", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "name", "}", ",", "}", "\...
// RenameBareMetalServer renames an existing bare metal server.
[ "RenameBareMetalServer", "renames", "an", "existing", "bare", "metal", "server", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L252-L259
train
JamesClonk/vultr
lib/bare_metal.go
TagBareMetalServer
func (c *Client) TagBareMetalServer(id, tag string) error { values := url.Values{ "SUBID": {id}, "tag": {tag}, } return c.post(`baremetal/tag_set`, values, nil) }
go
func (c *Client) TagBareMetalServer(id, tag string) error { values := url.Values{ "SUBID": {id}, "tag": {tag}, } return c.post(`baremetal/tag_set`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "TagBareMetalServer", "(", "id", ",", "tag", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "tag", "}", ",", "}", "\n\n",...
// TagBareMetalServer replaces the tag on an existing bare metal server.
[ "TagBareMetalServer", "replaces", "the", "tag", "on", "an", "existing", "bare", "metal", "server", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L262-L269
train
JamesClonk/vultr
lib/bare_metal.go
ReinstallBareMetalServer
func (c *Client) ReinstallBareMetalServer(id string) error { values := url.Values{ "SUBID": {id}, } return c.post(`baremetal/reinstall`, values, nil) }
go
func (c *Client) ReinstallBareMetalServer(id string) error { values := url.Values{ "SUBID": {id}, } return c.post(`baremetal/reinstall`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "ReinstallBareMetalServer", "(", "id", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "}", "\n\n", "return", "c", ".", "post", "(", "`baremetal/reins...
// ReinstallBareMetalServer reinstalls the operating system on an existing bare metal server.
[ "ReinstallBareMetalServer", "reinstalls", "the", "operating", "system", "on", "an", "existing", "bare", "metal", "server", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L290-L296
train
JamesClonk/vultr
lib/bare_metal.go
ListOSforBareMetalServer
func (c *Client) ListOSforBareMetalServer(id string) ([]OS, error) { var osMap map[string]OS if err := c.get(`baremetal/os_change_list?SUBID=`+id, &osMap); err != nil { return nil, err } var os []OS for _, o := range osMap { os = append(os, o) } sort.Sort(oses(os)) return os, nil }
go
func (c *Client) ListOSforBareMetalServer(id string) ([]OS, error) { var osMap map[string]OS if err := c.get(`baremetal/os_change_list?SUBID=`+id, &osMap); err != nil { return nil, err } var os []OS for _, o := range osMap { os = append(os, o) } sort.Sort(oses(os)) return os, nil }
[ "func", "(", "c", "*", "Client", ")", "ListOSforBareMetalServer", "(", "id", "string", ")", "(", "[", "]", "OS", ",", "error", ")", "{", "var", "osMap", "map", "[", "string", "]", "OS", "\n", "if", "err", ":=", "c", ".", "get", "(", "`baremetal/os_...
// ListOSforBareMetalServer lists all available operating systems to which an existing bare metal server can be changed.
[ "ListOSforBareMetalServer", "lists", "all", "available", "operating", "systems", "to", "which", "an", "existing", "bare", "metal", "server", "can", "be", "changed", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L309-L321
train
JamesClonk/vultr
lib/bare_metal.go
BandwidthOfBareMetalServer
func (c *Client) BandwidthOfBareMetalServer(id string) ([]map[string]string, error) { var bandwidthMap map[string][][]interface{} if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil { return nil, err } var bandwidth []map[string]string // parse incoming bytes for _, b := range bandwidthMap["incoming_bytes"] { bMap := make(map[string]string) bMap["date"] = fmt.Sprintf("%v", b[0]) var bytes int64 switch b[1].(type) { case float64: bytes = int64(b[1].(float64)) case int64: bytes = b[1].(int64) } bMap["incoming"] = fmt.Sprintf("%v", bytes) bandwidth = append(bandwidth, bMap) } // parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match) for _, b := range bandwidthMap["outgoing_bytes"] { for i := range bandwidth { if bandwidth[i]["date"] == fmt.Sprintf("%v", b[0]) { var bytes int64 switch b[1].(type) { case float64: bytes = int64(b[1].(float64)) case int64: bytes = b[1].(int64) } bandwidth[i]["outgoing"] = fmt.Sprintf("%v", bytes) break } } } return bandwidth, nil }
go
func (c *Client) BandwidthOfBareMetalServer(id string) ([]map[string]string, error) { var bandwidthMap map[string][][]interface{} if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil { return nil, err } var bandwidth []map[string]string // parse incoming bytes for _, b := range bandwidthMap["incoming_bytes"] { bMap := make(map[string]string) bMap["date"] = fmt.Sprintf("%v", b[0]) var bytes int64 switch b[1].(type) { case float64: bytes = int64(b[1].(float64)) case int64: bytes = b[1].(int64) } bMap["incoming"] = fmt.Sprintf("%v", bytes) bandwidth = append(bandwidth, bMap) } // parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match) for _, b := range bandwidthMap["outgoing_bytes"] { for i := range bandwidth { if bandwidth[i]["date"] == fmt.Sprintf("%v", b[0]) { var bytes int64 switch b[1].(type) { case float64: bytes = int64(b[1].(float64)) case int64: bytes = b[1].(int64) } bandwidth[i]["outgoing"] = fmt.Sprintf("%v", bytes) break } } } return bandwidth, nil }
[ "func", "(", "c", "*", "Client", ")", "BandwidthOfBareMetalServer", "(", "id", "string", ")", "(", "[", "]", "map", "[", "string", "]", "string", ",", "error", ")", "{", "var", "bandwidthMap", "map", "[", "string", "]", "[", "]", "[", "]", "interface...
// BandwidthOfBareMetalServer retrieves the bandwidth used by a bare metal server.
[ "BandwidthOfBareMetalServer", "retrieves", "the", "bandwidth", "used", "by", "a", "bare", "metal", "server", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L333-L373
train
JamesClonk/vultr
lib/bare_metal.go
ChangeApplicationofBareMetalServer
func (c *Client) ChangeApplicationofBareMetalServer(id string, appID string) error { values := url.Values{ "SUBID": {id}, "APPID": {appID}, } return c.post(`baremetal/app_change`, values, nil) }
go
func (c *Client) ChangeApplicationofBareMetalServer(id string, appID string) error { values := url.Values{ "SUBID": {id}, "APPID": {appID}, } return c.post(`baremetal/app_change`, values, nil) }
[ "func", "(", "c", "*", "Client", ")", "ChangeApplicationofBareMetalServer", "(", "id", "string", ",", "appID", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "id", "}", ",", "\"", "\"", ":", "{", "appID"...
// ChangeApplicationofBareMetalServer changes the bare metal server to a different application.
[ "ChangeApplicationofBareMetalServer", "changes", "the", "bare", "metal", "server", "to", "a", "different", "application", "." ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L376-L383
train
JamesClonk/vultr
lib/dns.go
GetDNSDomains
func (c *Client) GetDNSDomains() (domains []DNSDomain, err error) { if err := c.get(`dns/list`, &domains); err != nil { return nil, err } sort.Sort(dnsdomains(domains)) return domains, nil }
go
func (c *Client) GetDNSDomains() (domains []DNSDomain, err error) { if err := c.get(`dns/list`, &domains); err != nil { return nil, err } sort.Sort(dnsdomains(domains)) return domains, nil }
[ "func", "(", "c", "*", "Client", ")", "GetDNSDomains", "(", ")", "(", "domains", "[", "]", "DNSDomain", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`dns/list`", ",", "&", "domains", ")", ";", "err", "!=", "nil", "{", ...
// GetDNSDomains returns a list of available domains on Vultr account
[ "GetDNSDomains", "returns", "a", "list", "of", "available", "domains", "on", "Vultr", "account" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L54-L60
train
JamesClonk/vultr
lib/dns.go
GetDNSRecords
func (c *Client) GetDNSRecords(domain string) (records []DNSRecord, err error) { if err := c.get(`dns/records?domain=`+domain, &records); err != nil { return nil, err } sort.Sort(dnsrecords(records)) return records, nil }
go
func (c *Client) GetDNSRecords(domain string) (records []DNSRecord, err error) { if err := c.get(`dns/records?domain=`+domain, &records); err != nil { return nil, err } sort.Sort(dnsrecords(records)) return records, nil }
[ "func", "(", "c", "*", "Client", ")", "GetDNSRecords", "(", "domain", "string", ")", "(", "records", "[", "]", "DNSRecord", ",", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "get", "(", "`dns/records?domain=`", "+", "domain", ",", "&", "rec...
// GetDNSRecords returns a list of all DNS records of a particular domain
[ "GetDNSRecords", "returns", "a", "list", "of", "all", "DNS", "records", "of", "a", "particular", "domain" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L63-L69
train
JamesClonk/vultr
lib/dns.go
CreateDNSDomain
func (c *Client) CreateDNSDomain(domain, serverIP string) error { values := url.Values{ "domain": {domain}, "serverip": {serverIP}, } if err := c.post(`dns/create_domain`, values, nil); err != nil { return err } return nil }
go
func (c *Client) CreateDNSDomain(domain, serverIP string) error { values := url.Values{ "domain": {domain}, "serverip": {serverIP}, } if err := c.post(`dns/create_domain`, values, nil); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "CreateDNSDomain", "(", "domain", ",", "serverIP", "string", ")", "error", "{", "values", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "domain", "}", ",", "\"", "\"", ":", "{", "serverIP", "}", ",", ...
// CreateDNSDomain creates a new DNS domain name on Vultr
[ "CreateDNSDomain", "creates", "a", "new", "DNS", "domain", "name", "on", "Vultr" ]
fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91
https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L72-L82
train