code
stringlengths
10
1.34M
language
stringclasses
1 value
package dragon import ( "http" ) func handleAdmin(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, admarticlesURL, http.StatusFound) }
Go
package dragon import ( "http" ) func handleRoot(w http.ResponseWriter, r *http.Request) { if len(r.URL.Path) == 1 { http.Redirect(w, r, newspageURL+"1", http.StatusFound) } }
Go
package dragon import ( "http" "template" "time" "os" "strconv" "math" "strings" "appengine" "appengine/datastore" ) type article struct { Title string Content []byte Date datastore.Time Kind string } type article4tmpl struct { Title string Content []byte Date string Kind string Ke...
Go
package dragon import ( "fmt" "http" "template" "time" "strconv" "os" "math" "io" "appengine" "appengine/datastore" "appengine/urlfetch" ) const recaptcha = `http://www.google.com/recaptcha/api/verify?privatekey=%s&remoteip=%s&challenge=%s&response=%s` type entry struct { Nick string Email string...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // Functions to parse block-level elements. // package blackfriday import ( "bytes" )...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // // Markdown parsing and processing // // // Blackfriday markdown processor. // // Tr...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // // HTML rendering backend // // package blackfriday import ( "bytes" "fmt" "strc...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // Functions to parse inline elements. // package blackfriday import ( "bytes" ) // ...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // // SmartyPants rendering // // package blackfriday import ( "bytes" ) type smarty...
Go
// // Blackfriday Markdown Processor // Available at http://github.com/russross/blackfriday // // Copyright © 2011 Russ Ross <russ@russross.com>. // Distributed under the Simplified BSD License. // See README.md for details. // // // // LaTeX rendering backend // // package blackfriday import ( "bytes" ) // Latex ...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can o...
Go
package mahonia // Data for GBK 2-byte codes. // GBK codes are represented in big-endian order. // Based on the 2-byte subset of http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/gb-18030-2005.ucm // Codes that aren't on the BMP. var unicodeToGBKExtra = map[rune]uint16{ 0x20087: 0xfe51, 0x20089: 0...
Go
package mahonia // Converters for the EUC-JP encoding import ( "sync" ) func init() { RegisterCharset(&Charset{ Name: "EUC-JP", Aliases: []string{"extended_unix_code_packed_format_for_japanese", "cseucpkdfmtjapanese"}, NewDecoder: func() Decoder { eucJPOnce.Do(makeEUCJPTable) return eucJPTable.Decod...
Go
package mahonia // decoding HTML entities import ( "sync" ) var entityOnce sync.Once // entityTrie is similar to mbcsTrie, but not identical. type htmlEntityTrie struct { runes [2]rune // Some HTML entities decode to two characters. children []htmlEntityTrie } var entityTrie htmlEntityTrie func buildEntityT...
Go
package mahonia // Converters for GBK encoding. func init() { RegisterCharset(&Charset{ Name: "GBK", NewDecoder: func() Decoder { return decodeGBKRune }, NewEncoder: func() Encoder { return encodeGBKRune }, }) } func decodeGBKRune(p []byte) (r rune, size int, status Status) { if len(p) == 0 { st...
Go
package mahonia var jis0208ToUnicode = [65536]uint16{ 0x2121: 0x3000, // IDEOGRAPHIC SPACE 0x2122: 0x3001, // IDEOGRAPHIC COMMA 0x2123: 0x3002, // IDEOGRAPHIC FULL STOP 0x2124: 0xFF0C, // FULLWIDTH COMMA 0x2125: 0xFF0E, // FULLWIDTH FULL STOP 0x2126: 0x30FB, // KATAKANA MIDDLE DOT 0x2127: 0xFF1A, // FULLWIDTH C...
Go
package mahonia // Converters for ASCII and ISO-8859-1 func init() { for i := 0; i < len(asciiCharsets); i++ { RegisterCharset(&asciiCharsets[i]) } } var asciiCharsets = []Charset{ { Name: "US-ASCII", NewDecoder: func() Decoder { return decodeASCIIRune }, NewEncoder: func() Encoder { return encodeAS...
Go
package mahonia import ( "io" "unicode/utf8" ) // Writer implements character-set encoding for an io.Writer object. type Writer struct { wr io.Writer encode Encoder inbuf []byte outbuf []byte } // NewWriter creates a new Writer that uses the receiver to encode text. func (e Encoder) NewWriter(wr io.Writer...
Go
package mahonia // This file is based on bufio.Reader in the Go standard library, // which has the following copyright notice: // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. import ( "io" "unicode/utf8" ...
Go
package mahonia // Converters for Big 5 encoding. import ( "sync" ) func init() { RegisterCharset(&Charset{ Name: "Big5", Aliases: []string{"csBig5"}, NewDecoder: func() Decoder { return decodeBig5Rune }, NewEncoder: func() Encoder { big5Once.Do(reverseBig5Table) return encodeBig5Rune }, }...
Go
package mahonia import ( "fmt" "sync" ) // Converters for simple 8-bit character sets. type eightBitInfo struct { Name string Aliases []string // the character used for characters that can't be converted SubstitutionChar byte // a string containing all 256 characters, in order. Repertoire string // us...
Go
package mahonia var jis0201ToUnicode = [256]uint16{ 0x20: 0x0020, // SPACE 0x21: 0x0021, // EXCLAMATION MARK 0x22: 0x0022, // QUOTATION MARK 0x23: 0x0023, // NUMBER SIGN 0x24: 0x0024, // DOLLAR SIGN 0x25: 0x0025, // PERCENT SIGN 0x26: 0x0026, // AMPERSAND 0x27: 0x0027, // APOSTROPHE 0x28: 0x0028, // LEFT PARE...
Go
package mahonia var big5ToUnicode = [65536]uint16{ 0xA140: 0x3000, // IDEOGRAPHIC SPACE 0xA141: 0xFF0C, // FULLWIDTH COMMA 0xA142: 0x3001, // IDEOGRAPHIC COMMA 0xA143: 0x3002, // IDEOGRAPHIC FULL STOP 0xA144: 0xFF0E, // FULLWIDTH FULL STOP 0xA145: 0x2022, // BULLET 0xA146: 0xFF1B, // FULLWIDTH SEMICOLON 0xA147...
Go
package mahonia // FallbackDecoder combines a series of Decoders into one. // If the first Decoder returns a status of INVALID_CHAR, the others are tried as well. // // Note: if the text to be decoded ends with a sequence of bytes that is not a valid character in the first charset, // but it could be the beginning of ...
Go
package main import ( "code.google.com/p/mahonia" "flag" "io" "log" "os" ) // An iconv workalike using mahonia. var from = flag.String("f", "utf-8", "source character set") var to = flag.String("t", "utf-8", "destination character set") func main() { flag.Parse() var r io.Reader = os.Stdin var w io.Writer ...
Go
package mahonia // Generic converters for multibyte character sets. // An mbcsTrie contains the data to convert from the character set to Unicode. // If a character would be encoded as "\x01\x02\x03", its unicode value would be found at t.children[1].children[2].children[3].rune // children either is nil or has 256 e...
Go
package mahonia var jis0212ToUnicode = [65536]uint16{ 0x222F: 0x02D8, // BREVE 0x2230: 0x02C7, // CARON (Mandarin Chinese third tone) 0x2231: 0x00B8, // CEDILLA 0x2232: 0x02D9, // DOT ABOVE (Mandarin Chinese light tone) 0x2233: 0x02DD, // DOUBLE ACUTE ACCENT 0x2234: 0x00AF, // MACRON 0x2235: 0x02DB, // OGONEK ...
Go
package mahonia import ( "unicode/utf16" ) func init() { for i := 0; i < len(utf16Charsets); i++ { RegisterCharset(&utf16Charsets[i]) } } var utf16Charsets = []Charset{ { Name: "UTF-16", NewDecoder: func() Decoder { var decodeRune Decoder return func(p []byte) (c rune, size int, status Status) { ...
Go
package mahonia import "unicode/utf8" func init() { RegisterCharset(&Charset{ Name: "UTF-8", NewDecoder: func() Decoder { return decodeUTF8Rune }, NewEncoder: func() Encoder { return encodeUTF8Rune }, }) } func decodeUTF8Rune(p []byte) (c rune, size int, status Status) { if len(p) == 0 { status = NO...
Go
package mahonia import "unicode/utf8" // Translate enables a Decoder to implement go-charset's Translator interface. func (d Decoder) Translate(data []byte, eof bool) (n int, cdata []byte, err error) { cdata = make([]byte, len(data)+1) destPos := 0 for n < len(data) { rune, size, status := d(data[n:]) switch...
Go
package mahonia // Data tables for 4-byte characters in GB18030 encoding. // Based on http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/gb-18030-2005.ucm // gb18030Linear converts a 32-bit big-endian representation of a 4-byte // character into a linearly-increasing integer, starting from the base /...
Go
package mahonia // Converters for the Shift-JIS encoding. import ( "sync" ) func init() { RegisterCharset(&Charset{ Name: "Shift_JIS", Aliases: []string{"MS_Kanji", "csShiftJIS", "SJIS"}, NewDecoder: func() Decoder { sjisOnce.Do(makeSjisTable) return sjisTable.Decoder() }, NewEncoder: func() Enc...
Go
package mahonia // Taken from /src/pkg/html/entity.go in the Go source code. // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //package html // entity is a map from HTML entity names to their values. The se...
Go
package mahonia import ( "sync" ) // Converters for GB18030 encoding. func init() { RegisterCharset(&Charset{ Name: "GB18030", NewDecoder: func() Decoder { gb18030Once.Do(buildGB18030Tables) return decodeGB18030Rune }, NewEncoder: func() Encoder { gb18030Once.Do(buildGB18030Tables) return encod...
Go
// This package is a character-set conversion library for Go. package mahonia import ( "bytes" "unicode" ) // Status is the type for the status return value from a Decoder or Encoder. type Status int const ( // SUCCESS means that the character was converted with no problems. SUCCESS = Status(iota) // INVALID_C...
Go
package mahonia // ConvertString converts a string from UTF-8 to e's encoding. func (e Encoder) ConvertString(s string) string { dest := make([]byte, len(s)+10) destPos := 0 for _, rune := range s { retry: size, status := e(dest[destPos:], rune) if status == NO_ROOM { newDest := make([]byte, len(dest)*2)...
Go
// A basic package to decode Wave files. package audio import ( "rog-go.googlecode.com/hg/exp/abc" "os" "fmt" "io" "encoding/binary" "reflect" "strings" ) func init() { Register("readwav", wInput, map[string]abc.Socket { "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{abc.StringT, abc.Female}, ...
Go
/* Go program to decode an audio stream of Morse code into a stream of ASCII. See the ALGORITHM file for a description of what's going on, and 'proof.hs' as the original proof-of-concept implementation of this algorithm in Haskell. */ package main import ( "fmt" "math" "rand" "sort" ) type token int ...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "flag" "fmt" "io" "math/rand" "os" "strings" "sync" "text/template" "time" "unicode" "unicode/utf8" ) var IsDebug *bool var server *string var commands = []*Command{ cmdBenchmark, cmdCompact, cmdFiler, cmdFix, cmdServer, cmdMaster, cmdUploa...
Go
package main import ( "code.google.com/p/weed-fs/go/util" "fmt" "runtime" ) var cmdVersion = &Command{ Run: runVersion, UsageLine: "version", Short: "print Weed File System version", Long: `Version prints the Weed File System version`, } func runVersion(cmd *Command, args []string) bool { if l...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/util" "code.google.com/p/weed-fs/go/weed/weed_server" "github.com/gorilla/mux" "net/http" "os" "runtime" "strconv" "strings" "time" ) func init() { cmdMaster.Run = runMaster // break init cycle } var cmdMaster = &Comma...
Go
package main import ( "archive/tar" "bytes" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "fmt" "os" "path" "strconv" "strings" "text/template" "time" ) func init() { cmdExport.Run = runExport // break init cycle cmdExport.IsDebug = cmdExport.Flag.Bool("debug", false, "enable...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/util" "code.google.com/p/weed-fs/go/weed/weed_server" "net/http" "os" "runtime" "strconv" "strings" "time" ) func init() { cmdVolume.Run = runVolume // break init cycle } var cmdVolume = &Command{ UsageLine: "volume -p...
Go
package main import ( "bufio" "code.google.com/p/weed-fs/go/glog" "fmt" "os" ) func init() { cmdShell.Run = runShell // break init cycle } var cmdShell = &Command{ UsageLine: "shell", Short: "run interactive commands, now just echo", Long: `run interactive commands. `, } var () func runShell(command...
Go
package main import ( "code.google.com/p/weed-fs/go/operation" "encoding/json" "fmt" "os" "path/filepath" ) var ( uploadReplication *string uploadCollection *string uploadDir *string include *string maxMB *int ) func init() { cmdUpload.Run = runUpload // break init cycle cm...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/util" "code.google.com/p/weed-fs/go/weed/weed_server" "github.com/gorilla/mux" "net/http" "os" "runtime" "strconv" "strings" "sync" "time" ) var ( filer FilerOptions ) func init() { cmdServer.Run = runServer // break...
Go
package main import ( "flag" "fmt" "os" "strings" ) type Command struct { // Run runs the command. // The args are the arguments after the command name. Run func(cmd *Command, args []string) bool // UsageLine is the one-line usage message. // The first word in the line is taken to be the command name. Usag...
Go
package main import ( "bufio" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/util" "fmt" "io" "math" "math/rand" "os" "runtime" "runtime/pprof" "sort" "strings" "sync" "time" ) type BenchmarkOptions struct { server *string concurre...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "os" "path" "strconv" ) func init() { cmdFix.Run = runFix // break init cycle cmdFix.IsDebug = cmdFix.Flag.Bool("debug", false, "enable debug mode") } var cmdFix = &Command{ UsageLine: "fix -dir=/tmp -volumeId=23...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/util" "code.google.com/p/weed-fs/go/weed/weed_server" "net/http" "os" "strconv" "time" ) var ( f FilerOptions ) type FilerOptions struct { master *string port *int collection ...
Go
package main import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" ) func init() { cmdCompact.Run = runCompact // break init cycle cmdCompact.IsDebug = cmdCompact.Flag.Bool("debug", false, "enable debug mode") } var cmdCompact = &Command{ UsageLine: "compact -dir=/tmp -volumeId=234...
Go
package main import ( "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/util" "fmt" "io" "io/ioutil" "os" "path" "strings" ) var ( downloadReplication *string downloadDir *string ) func init() { cmdDownload.Run = runDownload // break init cycle cmdDownload.IsDebug = cmdDownlo...
Go
package weed_server import ( proto "code.google.com/p/goprotobuf/proto" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/topology" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" "io/ioutil" "net/htt...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "encoding/json" "github.com/goraft/raft" "io/ioutil" "net/http" "strings" ) // Handles incoming RAFT joins. func (s *RaftServer) joinHandler(w http.ResponseWriter, req *http.Request) { glog.V(0).Infoln("P...
Go
package weed_server import ( "bytes" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/stats" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/util" "encoding/json" "fmt" "net" "net/http" "path/filepath" "strconv" "strings" ) va...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/sequence" "code.google.com/p/weed-fs/go/topology" "code.google.com/p/weed-fs/go/util" "errors" "github.com/goraft/raft" "github.com/gorilla/mux" "net/http" "net/http/httputil" "net/url" "sync" ) type MasterServer...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "net/http" ) func (vs *VolumeServer) vacuumVolumeCheckHandler(w http.ResponseWriter, r *http.Request) { err, ret := vs.store.CheckCompactVolume(r.FormValue("volume"), r.FormValue("garbageThreshold")) if err == nil { writeJsonQuiet(w, r, map[string...
Go
package weed_server import ( "bytes" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/stats" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/topology" "github.com/disintegration/imaging" "image" "image/gif" "image/jpeg" "image/pn...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/stats" "code.google.com/p/weed-fs/go/util" "net/http" "path/filepath" ) func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) { m := make(map[string]interface{}) m["Version"] = util.VERSION m...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "math/rand" "net/http" "strconv" "time" ) type VolumeServer struct { masterNode string pulseSeconds int dataCenter string rack string whiteList []string store *storage.Store } fun...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" "github.com/syndtr/goleveldb/leveldb" "io" "io/ioutil" "math/rand" "net/http" "net/url" "strconv" "strings" ) func (fs *FilerServer) filer...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/filer" "code.google.com/p/weed-fs/go/glog" "net/http" "strconv" ) type FilerServer struct { port string master string collection string filer filer.Filer } func NewFilerServer(r *http.ServeMux, port int, master string, dir string, coll...
Go
package weed_server import ( "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/stats" "code.google.com/p/weed-fs/go/storage" "net/http" "strconv" "strings" ) func (ms *MasterServer) lookupVolumeId(vids []string, collection string) (volumeLocations map[string]operation.LookupResult) { volum...
Go
package weed_server import ( "bytes" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/topology" "encoding/json" "errors" "fmt" "github.com/goraft/raft" "github.com/gorilla/mux" "io/ioutil" "math/rand" "net/http" "net/url" "strings" "time" ) type RaftServer struct { peers []string ...
Go
package topology import ( "bytes" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/util" "net/http" "strconv" ) func ReplicatedWrite(masterNode string, s *storage.Store, volumeId storage.VolumeId, needle *storage.N...
Go
package topology import () type DataCenter struct { NodeImpl } func NewDataCenter(id string) *DataCenter { dc := &DataCenter{} dc.id = NodeId(id) dc.nodeType = "DataCenter" dc.children = make(map[NodeId]Node) dc.NodeImpl.value = dc return dc } func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack { f...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" ) type Collection struct { Name string volumeSizeLimit uint64 replicaType2VolumeLayout []*VolumeLayout } func NewCollection(name string, volumeSizeLimit uint64) *Collection { c := &...
Go
package topology import ( "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" "net/url" ) type AllocateVolumeResult struct { Error string } func AllocateVolume(dn *DataNode, vid storage.VolumeId, collection string, rp *storage.ReplicaPlacement) error { values :=...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "strconv" ) type DataNode struct { NodeImpl volumes map[storage.VolumeId]storage.VolumeInfo Ip string Port int PublicUrl string LastSeen int64 // unix time in seconds Dead bool } func Ne...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "math/rand" "time" ) func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string) { go func() { for { if t.IsLeader() { freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep inte...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" "net/url" "time" ) func batchVacuumVolumeCheck(vl *VolumeLayout, vid storage.VolumeId, locationlist *VolumeLocationList, garbageThreshold string) boo...
Go
package topology import ( "strconv" "time" ) type Rack struct { NodeImpl } func NewRack(id string) *Rack { r := &Rack{} r.id = NodeId(id) r.nodeType = "Rack" r.children = make(map[NodeId]Node) r.NodeImpl.value = r return r } func (r *Rack) FindDataNode(ip string, port int) *DataNode { for _, c := range r....
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "fmt" "math/rand" "sync" ) /* This package is created to resolve these replica placement issues: 1. growth factor for each replica level, e.g., add 10 volumes for 1 copy, 20 volumes for 2 copies, 30 volumes for 3...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "errors" "math/rand" "sync" ) // mapping from volume to its locations, inverted from server to volume type VolumeLayout struct { rp *storage.ReplicaPlacement vid2location map[storage.VolumeId]*V...
Go
package topology import () func (t *Topology) ToMap() interface{} { m := make(map[string]interface{}) m["Max"] = t.GetMaxVolumeCount() m["Free"] = t.FreeSpace() var dcs []interface{} for _, c := range t.Children() { dc := c.(*DataCenter) dcs = append(dcs, dc.ToMap()) } m["DataCenters"] = dcs var layouts [...
Go
package topology import () type VolumeLocationList struct { list []*DataNode } func NewVolumeLocationList() *VolumeLocationList { return &VolumeLocationList{} } func (dnll *VolumeLocationList) Head() *DataNode { return dnll.list[0] } func (dnll *VolumeLocationList) Length() int { return len(dnll.list) } func ...
Go
package topology import ( "encoding/xml" ) type loc struct { dcName string rackName string } type rack struct { Name string `xml:"name,attr"` Ips []string `xml:"Ip"` } type dataCenter struct { Name string `xml:"name,attr"` Racks []rack `xml:"Rack"` } type topology struct { DataCenters []dataCenter `xml:...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/sequence" "code.google.com/p/weed-fs/go/storage" "errors" "github.com/goraft/raft" "io/ioutil" "math/rand" ) type Topology struct { NodeImpl collectionMap map[string]*Collect...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "errors" "math/rand" "strings" ) type NodeId string type Node interface { Id() NodeId String() string FreeSpace() int ReserveOneVolume(r int) (*DataNode, error) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelt...
Go
package topology import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/storage" "github.com/goraft/raft" ) type MaxVolumeIdCommand struct { MaxVolumeId storage.VolumeId `json:"maxVolumeId"` } func NewMaxVolumeIdCommand(value storage.VolumeId) *MaxVolumeIdCommand { return &MaxVolumeIdCommand...
Go
package filer import () type DirectoryId int32 type DirectoryEntry struct { Name string //dir name without path Id DirectoryId } type DirectoryManager interface { FindDirectory(dirPath string) (DirectoryId, error) ListDirectories(dirPath string) (dirNames []DirectoryEntry, err error) MakeDirectory(currentDir...
Go
package filer import ( "bytes" "code.google.com/p/weed-fs/go/glog" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" ) type FileListInLevelDb struct { db *leveldb.DB } func NewFileListInLevelDb(dir string) (fl *FileListInLevelDb, err error) { fl = &FileListInLevelDb{} if fl.db, ...
Go
package filer import ( "code.google.com/p/weed-fs/go/operation" "errors" "fmt" "path/filepath" "strings" ) type FilerEmbedded struct { master string directories *DirectoryManagerInMap files *FileListInLevelDb } func NewFilerEmbedded(master string, dir string) (filer *FilerEmbedded, err error) { d...
Go
package filer import () type FileId string //file id on weedfs type FileEntry struct { Name string //file name without path Id FileId } type Filer interface { CreateFile(filePath string, fid string) (err error) FindFile(filePath string) (fid string, err error) ListDirectories(dirPath string) (dirs []Director...
Go
package filer import ( "bufio" "code.google.com/p/weed-fs/go/util" "fmt" "io" "os" "path/filepath" "strconv" "strings" ) type DirectoryEntryInMap struct { Name string Parent *DirectoryEntryInMap SubDirectories map[string]*DirectoryEntryInMap Id DirectoryId } type DirectoryMa...
Go
package storage import () type NeedleValue struct { Key Key Offset uint32 `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G Size uint32 `comment:"Size of the data portion"` } const ( batch = 100000 ) type Key uint64 type CompactSection struct { values []NeedleValue overflow map[K...
Go
package storage import ( "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/util" "fmt" "io" "os" ) type NeedleMapper interface { Put(key uint64, offset uint32, size uint32) (int, error) Get(key uint64) (element *NeedleValue, ok bool) Delete(key uint64) error Close() Destroy() error ContentS...
Go
package storage import ( "bytes" "code.google.com/p/weed-fs/go/glog" "compress/flate" "compress/gzip" "io/ioutil" "strings" ) /* * Default more not to gzip since gzip can be done on client side. */ func IsGzippable(ext, mtype string) bool { if strings.HasPrefix(mtype, "text/") { return true } switch ext {...
Go
package storage import ( "code.google.com/p/weed-fs/go/operation" ) type VolumeInfo struct { Id VolumeId Size uint64 ReplicaPlacement *ReplicaPlacement Collection string Version Version FileCount int DeleteCount int DeletedByteCount uint64 ReadOnly ...
Go
package storage import ( "errors" "fmt" ) const ( ReplicaPlacementCount = 9 ) type ReplicaPlacement struct { SameRackCount int DiffRackCount int DiffDataCenterCount int } func NewReplicaPlacementFromString(t string) (*ReplicaPlacement, error) { rp := &ReplicaPlacement{} for i, c := range t { c...
Go
package storage import ( proto "code.google.com/p/goprotobuf/proto" "code.google.com/p/weed-fs/go/glog" "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" "fmt" "io/ioutil" "math/rand" "strconv" "strings" ) type DiskLocation struct { Directory string...
Go
package storage import ( "bytes" "code.google.com/p/weed-fs/go/glog" "errors" "fmt" "io" "os" "path" "sync" "time" ) const ( SuperBlockSize = 8 ) type SuperBlock struct { Version Version ReplicaPlacement *ReplicaPlacement } func (s *SuperBlock) Bytes() []byte { header := make([]byte, SuperBloc...
Go