id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
25,900
goraft/raft
append_entries.go
newAppendEntriesRequest
func newAppendEntriesRequest(term uint64, prevLogIndex uint64, prevLogTerm uint64, commitIndex uint64, leaderName string, entries []*LogEntry) *AppendEntriesRequest { pbEntries := make([]*protobuf.LogEntry, len(entries)) for i := range entries { pbEntries[i] = entries[i].pb } return &AppendEntriesRequest{ Te...
go
func newAppendEntriesRequest(term uint64, prevLogIndex uint64, prevLogTerm uint64, commitIndex uint64, leaderName string, entries []*LogEntry) *AppendEntriesRequest { pbEntries := make([]*protobuf.LogEntry, len(entries)) for i := range entries { pbEntries[i] = entries[i].pb } return &AppendEntriesRequest{ Te...
[ "func", "newAppendEntriesRequest", "(", "term", "uint64", ",", "prevLogIndex", "uint64", ",", "prevLogTerm", "uint64", ",", "commitIndex", "uint64", ",", "leaderName", "string", ",", "entries", "[", "]", "*", "LogEntry", ")", "*", "AppendEntriesRequest", "{", "p...
// Creates a new AppendEntries request.
[ "Creates", "a", "new", "AppendEntries", "request", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L29-L45
25,901
goraft/raft
append_entries.go
Encode
func (req *AppendEntriesRequest) Encode(w io.Writer) (int, error) { pb := &protobuf.AppendEntriesRequest{ Term: proto.Uint64(req.Term), PrevLogIndex: proto.Uint64(req.PrevLogIndex), PrevLogTerm: proto.Uint64(req.PrevLogTerm), CommitIndex: proto.Uint64(req.CommitIndex), LeaderName: proto.String(re...
go
func (req *AppendEntriesRequest) Encode(w io.Writer) (int, error) { pb := &protobuf.AppendEntriesRequest{ Term: proto.Uint64(req.Term), PrevLogIndex: proto.Uint64(req.PrevLogIndex), PrevLogTerm: proto.Uint64(req.PrevLogTerm), CommitIndex: proto.Uint64(req.CommitIndex), LeaderName: proto.String(re...
[ "func", "(", "req", "*", "AppendEntriesRequest", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "(", "int", ",", "error", ")", "{", "pb", ":=", "&", "protobuf", ".", "AppendEntriesRequest", "{", "Term", ":", "proto", ".", "Uint64", "(", "req", "....
// Encodes the AppendEntriesRequest to a buffer. Returns the number of bytes // written and any error that may have occurred.
[ "Encodes", "the", "AppendEntriesRequest", "to", "a", "buffer", ".", "Returns", "the", "number", "of", "bytes", "written", "and", "any", "error", "that", "may", "have", "occurred", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L49-L65
25,902
goraft/raft
append_entries.go
Decode
func (req *AppendEntriesRequest) Decode(r io.Reader) (int, error) { data, err := ioutil.ReadAll(r) if err != nil { return -1, err } pb := new(protobuf.AppendEntriesRequest) if err := proto.Unmarshal(data, pb); err != nil { return -1, err } req.Term = pb.GetTerm() req.PrevLogIndex = pb.GetPrevLogIndex() ...
go
func (req *AppendEntriesRequest) Decode(r io.Reader) (int, error) { data, err := ioutil.ReadAll(r) if err != nil { return -1, err } pb := new(protobuf.AppendEntriesRequest) if err := proto.Unmarshal(data, pb); err != nil { return -1, err } req.Term = pb.GetTerm() req.PrevLogIndex = pb.GetPrevLogIndex() ...
[ "func", "(", "req", "*", "AppendEntriesRequest", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "(", "int", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n\n", "if", "err", "!=", "nil", "{", "ret...
// Decodes the AppendEntriesRequest from a buffer. Returns the number of bytes read and // any error that occurs.
[ "Decodes", "the", "AppendEntriesRequest", "from", "a", "buffer", ".", "Returns", "the", "number", "of", "bytes", "read", "and", "any", "error", "that", "occurs", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L69-L89
25,903
goraft/raft
append_entries.go
newAppendEntriesResponse
func newAppendEntriesResponse(term uint64, success bool, index uint64, commitIndex uint64) *AppendEntriesResponse { pb := &protobuf.AppendEntriesResponse{ Term: proto.Uint64(term), Index: proto.Uint64(index), Success: proto.Bool(success), CommitIndex: proto.Uint64(commitIndex), } return &Ap...
go
func newAppendEntriesResponse(term uint64, success bool, index uint64, commitIndex uint64) *AppendEntriesResponse { pb := &protobuf.AppendEntriesResponse{ Term: proto.Uint64(term), Index: proto.Uint64(index), Success: proto.Bool(success), CommitIndex: proto.Uint64(commitIndex), } return &Ap...
[ "func", "newAppendEntriesResponse", "(", "term", "uint64", ",", "success", "bool", ",", "index", "uint64", ",", "commitIndex", "uint64", ")", "*", "AppendEntriesResponse", "{", "pb", ":=", "&", "protobuf", ".", "AppendEntriesResponse", "{", "Term", ":", "proto",...
// Creates a new AppendEntries response.
[ "Creates", "a", "new", "AppendEntries", "response", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L92-L103
25,904
goraft/raft
append_entries.go
Encode
func (resp *AppendEntriesResponse) Encode(w io.Writer) (int, error) { b, err := proto.Marshal(resp.pb) if err != nil { return -1, err } return w.Write(b) }
go
func (resp *AppendEntriesResponse) Encode(w io.Writer) (int, error) { b, err := proto.Marshal(resp.pb) if err != nil { return -1, err } return w.Write(b) }
[ "func", "(", "resp", "*", "AppendEntriesResponse", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "(", "int", ",", "error", ")", "{", "b", ",", "err", ":=", "proto", ".", "Marshal", "(", "resp", ".", "pb", ")", "\n", "if", "err", "!=", "nil",...
// Encodes the AppendEntriesResponse to a buffer. Returns the number of bytes // written and any error that may have occurred.
[ "Encodes", "the", "AppendEntriesResponse", "to", "a", "buffer", ".", "Returns", "the", "number", "of", "bytes", "written", "and", "any", "error", "that", "may", "have", "occurred", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L123-L130
25,905
goraft/raft
append_entries.go
Decode
func (resp *AppendEntriesResponse) Decode(r io.Reader) (int, error) { data, err := ioutil.ReadAll(r) if err != nil { return -1, err } resp.pb = new(protobuf.AppendEntriesResponse) if err := proto.Unmarshal(data, resp.pb); err != nil { return -1, err } return len(data), nil }
go
func (resp *AppendEntriesResponse) Decode(r io.Reader) (int, error) { data, err := ioutil.ReadAll(r) if err != nil { return -1, err } resp.pb = new(protobuf.AppendEntriesResponse) if err := proto.Unmarshal(data, resp.pb); err != nil { return -1, err } return len(data), nil }
[ "func", "(", "resp", "*", "AppendEntriesResponse", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "(", "int", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "ret...
// Decodes the AppendEntriesResponse from a buffer. Returns the number of bytes read and // any error that occurs.
[ "Decodes", "the", "AppendEntriesResponse", "from", "a", "buffer", ".", "Returns", "the", "number", "of", "bytes", "read", "and", "any", "error", "that", "occurs", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/append_entries.go#L134-L146
25,906
goraft/raft
server.go
Peers
func (s *server) Peers() map[string]*Peer { s.mutex.Lock() defer s.mutex.Unlock() peers := make(map[string]*Peer) for name, peer := range s.peers { peers[name] = peer.clone() } return peers }
go
func (s *server) Peers() map[string]*Peer { s.mutex.Lock() defer s.mutex.Unlock() peers := make(map[string]*Peer) for name, peer := range s.peers { peers[name] = peer.clone() } return peers }
[ "func", "(", "s", "*", "server", ")", "Peers", "(", ")", "map", "[", "string", "]", "*", "Peer", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "peers", ":=", "make", "(", "ma...
// Retrieves a copy of the peer data.
[ "Retrieves", "a", "copy", "of", "the", "peer", "data", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L241-L250
25,907
goraft/raft
server.go
Transporter
func (s *server) Transporter() Transporter { s.mutex.RLock() defer s.mutex.RUnlock() return s.transporter }
go
func (s *server) Transporter() Transporter { s.mutex.RLock() defer s.mutex.RUnlock() return s.transporter }
[ "func", "(", "s", "*", "server", ")", "Transporter", "(", ")", "Transporter", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "s", ".", "transporter", "\n", "}" ]
// Retrieves the object that transports requests.
[ "Retrieves", "the", "object", "that", "transports", "requests", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L253-L257
25,908
goraft/raft
server.go
State
func (s *server) State() string { s.mutex.RLock() defer s.mutex.RUnlock() return s.state }
go
func (s *server) State() string { s.mutex.RLock() defer s.mutex.RUnlock() return s.state }
[ "func", "(", "s", "*", "server", ")", "State", "(", ")", "string", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "s", ".", "state", "\n", "}" ]
// Retrieves the current state of the server.
[ "Retrieves", "the", "current", "state", "of", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L281-L285
25,909
goraft/raft
server.go
setState
func (s *server) setState(state string) { s.mutex.Lock() defer s.mutex.Unlock() // Temporarily store previous values. prevState := s.state prevLeader := s.leader // Update state and leader. s.state = state if state == Leader { s.leader = s.Name() s.syncedPeer = make(map[string]bool) } // Dispatch state...
go
func (s *server) setState(state string) { s.mutex.Lock() defer s.mutex.Unlock() // Temporarily store previous values. prevState := s.state prevLeader := s.leader // Update state and leader. s.state = state if state == Leader { s.leader = s.Name() s.syncedPeer = make(map[string]bool) } // Dispatch state...
[ "func", "(", "s", "*", "server", ")", "setState", "(", "state", "string", ")", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "// Temporarily store previous values.", "prevState", ":=", ...
// Sets the state of the server.
[ "Sets", "the", "state", "of", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L288-L309
25,910
goraft/raft
server.go
Term
func (s *server) Term() uint64 { s.mutex.RLock() defer s.mutex.RUnlock() return s.currentTerm }
go
func (s *server) Term() uint64 { s.mutex.RLock() defer s.mutex.RUnlock() return s.currentTerm }
[ "func", "(", "s", "*", "server", ")", "Term", "(", ")", "uint64", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "s", ".", "currentTerm", "\n", "}" ]
// Retrieves the current term of the server.
[ "Retrieves", "the", "current", "term", "of", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L312-L316
25,911
goraft/raft
server.go
CommitIndex
func (s *server) CommitIndex() uint64 { s.log.mutex.RLock() defer s.log.mutex.RUnlock() return s.log.commitIndex }
go
func (s *server) CommitIndex() uint64 { s.log.mutex.RLock() defer s.log.mutex.RUnlock() return s.log.commitIndex }
[ "func", "(", "s", "*", "server", ")", "CommitIndex", "(", ")", "uint64", "{", "s", ".", "log", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "log", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "s", ".", "log", ".", ...
// Retrieves the current commit index of the server.
[ "Retrieves", "the", "current", "commit", "index", "of", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L319-L323
25,912
goraft/raft
server.go
LogEntries
func (s *server) LogEntries() []*LogEntry { s.log.mutex.RLock() defer s.log.mutex.RUnlock() return s.log.entries }
go
func (s *server) LogEntries() []*LogEntry { s.log.mutex.RLock() defer s.log.mutex.RUnlock() return s.log.entries }
[ "func", "(", "s", "*", "server", ")", "LogEntries", "(", ")", "[", "]", "*", "LogEntry", "{", "s", ".", "log", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "log", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "s", ...
// A list of all the log entries. This should only be used for debugging purposes.
[ "A", "list", "of", "all", "the", "log", "entries", ".", "This", "should", "only", "be", "used", "for", "debugging", "purposes", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L336-L340
25,913
goraft/raft
server.go
GetState
func (s *server) GetState() string { s.mutex.RLock() defer s.mutex.RUnlock() return fmt.Sprintf("Name: %s, State: %s, Term: %v, CommitedIndex: %v ", s.name, s.state, s.currentTerm, s.log.commitIndex) }
go
func (s *server) GetState() string { s.mutex.RLock() defer s.mutex.RUnlock() return fmt.Sprintf("Name: %s, State: %s, Term: %v, CommitedIndex: %v ", s.name, s.state, s.currentTerm, s.log.commitIndex) }
[ "func", "(", "s", "*", "server", ")", "GetState", "(", ")", "string", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ...
// Get the state of the server for debugging
[ "Get", "the", "state", "of", "the", "server", "for", "debugging" ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L348-L352
25,914
goraft/raft
server.go
SetElectionTimeout
func (s *server) SetElectionTimeout(duration time.Duration) { s.mutex.Lock() defer s.mutex.Unlock() s.electionTimeout = duration }
go
func (s *server) SetElectionTimeout(duration time.Duration) { s.mutex.Lock() defer s.mutex.Unlock() s.electionTimeout = duration }
[ "func", "(", "s", "*", "server", ")", "SetElectionTimeout", "(", "duration", "time", ".", "Duration", ")", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n", "s", ".", "electionTimeout", ...
// Sets the election timeout.
[ "Sets", "the", "election", "timeout", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L387-L391
25,915
goraft/raft
server.go
SetHeartbeatInterval
func (s *server) SetHeartbeatInterval(duration time.Duration) { s.mutex.Lock() defer s.mutex.Unlock() s.heartbeatInterval = duration for _, peer := range s.peers { peer.setHeartbeatInterval(duration) } }
go
func (s *server) SetHeartbeatInterval(duration time.Duration) { s.mutex.Lock() defer s.mutex.Unlock() s.heartbeatInterval = duration for _, peer := range s.peers { peer.setHeartbeatInterval(duration) } }
[ "func", "(", "s", "*", "server", ")", "SetHeartbeatInterval", "(", "duration", "time", ".", "Duration", ")", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "s", ".", "heartbeatInterva...
// Sets the heartbeat timeout.
[ "Sets", "the", "heartbeat", "timeout", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L405-L413
25,916
goraft/raft
server.go
Start
func (s *server) Start() error { // Exit if the server is already running. if s.Running() { return fmt.Errorf("raft.Server: Server already running[%v]", s.state) } if err := s.Init(); err != nil { return err } // stopped needs to be allocated each time server starts // because it is closed at `Stop`. s.st...
go
func (s *server) Start() error { // Exit if the server is already running. if s.Running() { return fmt.Errorf("raft.Server: Server already running[%v]", s.state) } if err := s.Init(); err != nil { return err } // stopped needs to be allocated each time server starts // because it is closed at `Stop`. s.st...
[ "func", "(", "s", "*", "server", ")", "Start", "(", ")", "error", "{", "// Exit if the server is already running.", "if", "s", ".", "Running", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "state", ")", "\n", "}", "\n...
// Start the raft server // If log entries exist then allow promotion to candidate if no AEs received. // If no log entries exist then wait for AEs from another node. // If no log entries exist and a self-join command is issued then // immediately become leader and commit entry.
[ "Start", "the", "raft", "server", "If", "log", "entries", "exist", "then", "allow", "promotion", "to", "candidate", "if", "no", "AEs", "received", ".", "If", "no", "log", "entries", "exist", "then", "wait", "for", "AEs", "from", "another", "node", ".", "...
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L437-L474
25,917
goraft/raft
server.go
Stop
func (s *server) Stop() { if s.State() == Stopped { return } close(s.stopped) // make sure all goroutines have stopped before we close the log s.routineGroup.Wait() s.log.close() s.setState(Stopped) }
go
func (s *server) Stop() { if s.State() == Stopped { return } close(s.stopped) // make sure all goroutines have stopped before we close the log s.routineGroup.Wait() s.log.close() s.setState(Stopped) }
[ "func", "(", "s", "*", "server", ")", "Stop", "(", ")", "{", "if", "s", ".", "State", "(", ")", "==", "Stopped", "{", "return", "\n", "}", "\n\n", "close", "(", "s", ".", "stopped", ")", "\n\n", "// make sure all goroutines have stopped before we close the...
// Shuts down the server.
[ "Shuts", "down", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L518-L530
25,918
goraft/raft
server.go
Running
func (s *server) Running() bool { s.mutex.RLock() defer s.mutex.RUnlock() return (s.state != Stopped && s.state != Initialized) }
go
func (s *server) Running() bool { s.mutex.RLock() defer s.mutex.RUnlock() return (s.state != Stopped && s.state != Initialized) }
[ "func", "(", "s", "*", "server", ")", "Running", "(", ")", "bool", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "(", "s", ".", "state", "!=", "Stopped", "&&", "s", ...
// Checks if the server is currently running.
[ "Checks", "if", "the", "server", "is", "currently", "running", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L533-L537
25,919
goraft/raft
server.go
send
func (s *server) send(value interface{}) (interface{}, error) { if !s.Running() { return nil, StopError } event := &ev{target: value, c: make(chan error, 1)} select { case s.c <- event: case <-s.stopped: return nil, StopError } select { case <-s.stopped: return nil, StopError case err := <-event.c: r...
go
func (s *server) send(value interface{}) (interface{}, error) { if !s.Running() { return nil, StopError } event := &ev{target: value, c: make(chan error, 1)} select { case s.c <- event: case <-s.stopped: return nil, StopError } select { case <-s.stopped: return nil, StopError case err := <-event.c: r...
[ "func", "(", "s", "*", "server", ")", "send", "(", "value", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "!", "s", ".", "Running", "(", ")", "{", "return", "nil", ",", "StopError", "\n", "}", "\n\n", "ev...
// Sends an event to the event loop to be processed. The function will wait // until the event is actually processed before returning.
[ "Sends", "an", "event", "to", "the", "event", "loop", "to", "be", "processed", ".", "The", "function", "will", "wait", "until", "the", "event", "is", "actually", "processed", "before", "returning", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L619-L636
25,920
goraft/raft
server.go
candidateLoop
func (s *server) candidateLoop() { // Clear leader value. prevLeader := s.leader s.leader = "" if prevLeader != s.leader { s.DispatchEvent(newEvent(LeaderChangeEventType, s.leader, prevLeader)) } lastLogIndex, lastLogTerm := s.log.lastInfo() doVote := true votesGranted := 0 var timeoutChan <-chan time.Time ...
go
func (s *server) candidateLoop() { // Clear leader value. prevLeader := s.leader s.leader = "" if prevLeader != s.leader { s.DispatchEvent(newEvent(LeaderChangeEventType, s.leader, prevLeader)) } lastLogIndex, lastLogTerm := s.log.lastInfo() doVote := true votesGranted := 0 var timeoutChan <-chan time.Time ...
[ "func", "(", "s", "*", "server", ")", "candidateLoop", "(", ")", "{", "// Clear leader value.", "prevLeader", ":=", "s", ".", "leader", "\n", "s", ".", "leader", "=", "\"", "\"", "\n", "if", "prevLeader", "!=", "s", ".", "leader", "{", "s", ".", "Dis...
// The event loop that is run when the server is in a Candidate state.
[ "The", "event", "loop", "that", "is", "run", "when", "the", "server", "is", "in", "a", "Candidate", "state", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L730-L808
25,921
goraft/raft
server.go
leaderLoop
func (s *server) leaderLoop() { logIndex, _ := s.log.lastInfo() // Update the peers prevLogIndex to leader's lastLogIndex and start heartbeat. s.debugln("leaderLoop.set.PrevIndex to ", logIndex) for _, peer := range s.peers { peer.setPrevLogIndex(logIndex) peer.startHeartbeat() } // Commit a NOP after the s...
go
func (s *server) leaderLoop() { logIndex, _ := s.log.lastInfo() // Update the peers prevLogIndex to leader's lastLogIndex and start heartbeat. s.debugln("leaderLoop.set.PrevIndex to ", logIndex) for _, peer := range s.peers { peer.setPrevLogIndex(logIndex) peer.startHeartbeat() } // Commit a NOP after the s...
[ "func", "(", "s", "*", "server", ")", "leaderLoop", "(", ")", "{", "logIndex", ",", "_", ":=", "s", ".", "log", ".", "lastInfo", "(", ")", "\n\n", "// Update the peers prevLogIndex to leader's lastLogIndex and start heartbeat.", "s", ".", "debugln", "(", "\"", ...
// The event loop that is run when the server is in a Leader state.
[ "The", "event", "loop", "that", "is", "run", "when", "the", "server", "is", "in", "a", "Leader", "state", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L811-L862
25,922
goraft/raft
server.go
processCommand
func (s *server) processCommand(command Command, e *ev) { s.debugln("server.command.process") // Create an entry for the command in the log. entry, err := s.log.createEntry(s.currentTerm, command, e) if err != nil { s.debugln("server.command.log.entry.error:", err) e.c <- err return } if err := s.log.app...
go
func (s *server) processCommand(command Command, e *ev) { s.debugln("server.command.process") // Create an entry for the command in the log. entry, err := s.log.createEntry(s.currentTerm, command, e) if err != nil { s.debugln("server.command.log.entry.error:", err) e.c <- err return } if err := s.log.app...
[ "func", "(", "s", "*", "server", ")", "processCommand", "(", "command", "Command", ",", "e", "*", "ev", ")", "{", "s", ".", "debugln", "(", "\"", "\"", ")", "\n\n", "// Create an entry for the command in the log.", "entry", ",", "err", ":=", "s", ".", "l...
// Processes a command.
[ "Processes", "a", "command", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L901-L925
25,923
goraft/raft
server.go
processAppendEntriesRequest
func (s *server) processAppendEntriesRequest(req *AppendEntriesRequest) (*AppendEntriesResponse, bool) { s.traceln("server.ae.process") if req.Term < s.currentTerm { s.debugln("server.ae.error: stale term") return newAppendEntriesResponse(s.currentTerm, false, s.log.currentIndex(), s.log.CommitIndex()), false }...
go
func (s *server) processAppendEntriesRequest(req *AppendEntriesRequest) (*AppendEntriesResponse, bool) { s.traceln("server.ae.process") if req.Term < s.currentTerm { s.debugln("server.ae.error: stale term") return newAppendEntriesResponse(s.currentTerm, false, s.log.currentIndex(), s.log.CommitIndex()), false }...
[ "func", "(", "s", "*", "server", ")", "processAppendEntriesRequest", "(", "req", "*", "AppendEntriesRequest", ")", "(", "*", "AppendEntriesResponse", ",", "bool", ")", "{", "s", ".", "traceln", "(", "\"", "\"", ")", "\n\n", "if", "req", ".", "Term", "<",...
// Processes the "append entries" request.
[ "Processes", "the", "append", "entries", "request", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L939-L985
25,924
goraft/raft
server.go
processAppendEntriesResponse
func (s *server) processAppendEntriesResponse(resp *AppendEntriesResponse) { // If we find a higher term then change to a follower and exit. if resp.Term() > s.Term() { s.updateCurrentTerm(resp.Term(), "") return } // panic response if it's not successful. if !resp.Success() { return } // if one peer suc...
go
func (s *server) processAppendEntriesResponse(resp *AppendEntriesResponse) { // If we find a higher term then change to a follower and exit. if resp.Term() > s.Term() { s.updateCurrentTerm(resp.Term(), "") return } // panic response if it's not successful. if !resp.Success() { return } // if one peer suc...
[ "func", "(", "s", "*", "server", ")", "processAppendEntriesResponse", "(", "resp", "*", "AppendEntriesResponse", ")", "{", "// If we find a higher term then change to a follower and exit.", "if", "resp", ".", "Term", "(", ")", ">", "s", ".", "Term", "(", ")", "{",...
// Processes the "append entries" response from the peer. This is only // processed when the server is a leader. Responses received during other // states are dropped.
[ "Processes", "the", "append", "entries", "response", "from", "the", "peer", ".", "This", "is", "only", "processed", "when", "the", "server", "is", "a", "leader", ".", "Responses", "received", "during", "other", "states", "are", "dropped", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L990-L1031
25,925
goraft/raft
server.go
processRequestVoteRequest
func (s *server) processRequestVoteRequest(req *RequestVoteRequest) (*RequestVoteResponse, bool) { // If the request is coming from an old term then reject it. if req.Term < s.Term() { s.debugln("server.rv.deny.vote: cause stale term") return newRequestVoteResponse(s.currentTerm, false), false } // If the ter...
go
func (s *server) processRequestVoteRequest(req *RequestVoteRequest) (*RequestVoteResponse, bool) { // If the request is coming from an old term then reject it. if req.Term < s.Term() { s.debugln("server.rv.deny.vote: cause stale term") return newRequestVoteResponse(s.currentTerm, false), false } // If the ter...
[ "func", "(", "s", "*", "server", ")", "processRequestVoteRequest", "(", "req", "*", "RequestVoteRequest", ")", "(", "*", "RequestVoteResponse", ",", "bool", ")", "{", "// If the request is coming from an old term then reject it.", "if", "req", ".", "Term", "<", "s",...
// Processes a "request vote" request.
[ "Processes", "a", "request", "vote", "request", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L1066-L1099
25,926
goraft/raft
server.go
RemovePeer
func (s *server) RemovePeer(name string) error { s.debugln("server.peer.remove: ", name, len(s.peers)) // Skip the Peer if it has the same name as the Server if name != s.Name() { // Return error if peer doesn't exist. peer := s.peers[name] if peer == nil { return fmt.Errorf("raft: Peer not found: %s", nam...
go
func (s *server) RemovePeer(name string) error { s.debugln("server.peer.remove: ", name, len(s.peers)) // Skip the Peer if it has the same name as the Server if name != s.Name() { // Return error if peer doesn't exist. peer := s.peers[name] if peer == nil { return fmt.Errorf("raft: Peer not found: %s", nam...
[ "func", "(", "s", "*", "server", ")", "RemovePeer", "(", "name", "string", ")", "error", "{", "s", ".", "debugln", "(", "\"", "\"", ",", "name", ",", "len", "(", "s", ".", "peers", ")", ")", "\n\n", "// Skip the Peer if it has the same name as the Server",...
// Removes a peer from the server.
[ "Removes", "a", "peer", "from", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L1134-L1171
25,927
goraft/raft
server.go
LoadSnapshot
func (s *server) LoadSnapshot() error { // Open snapshot/ directory. dir, err := os.OpenFile(path.Join(s.path, "snapshot"), os.O_RDONLY, 0) if err != nil { s.debugln("cannot.open.snapshot: ", err) return err } // Retrieve a list of all snapshots. filenames, err := dir.Readdirnames(-1) if err != nil { dir....
go
func (s *server) LoadSnapshot() error { // Open snapshot/ directory. dir, err := os.OpenFile(path.Join(s.path, "snapshot"), os.O_RDONLY, 0) if err != nil { s.debugln("cannot.open.snapshot: ", err) return err } // Retrieve a list of all snapshots. filenames, err := dir.Readdirnames(-1) if err != nil { dir....
[ "func", "(", "s", "*", "server", ")", "LoadSnapshot", "(", ")", "error", "{", "// Open snapshot/ directory.", "dir", ",", "err", ":=", "os", ".", "OpenFile", "(", "path", ".", "Join", "(", "s", ".", "path", ",", "\"", "\"", ")", ",", "os", ".", "O_...
// Load a snapshot at restart
[ "Load", "a", "snapshot", "at", "restart" ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L1316-L1393
25,928
goraft/raft
server.go
readConf
func (s *server) readConf() error { confPath := path.Join(s.path, "conf") s.debugln("readConf.open ", confPath) // open conf file b, err := ioutil.ReadFile(confPath) if err != nil { return nil } conf := &Config{} if err = json.Unmarshal(b, conf); err != nil { return err } s.log.updateCommitIndex(conf...
go
func (s *server) readConf() error { confPath := path.Join(s.path, "conf") s.debugln("readConf.open ", confPath) // open conf file b, err := ioutil.ReadFile(confPath) if err != nil { return nil } conf := &Config{} if err = json.Unmarshal(b, conf); err != nil { return err } s.log.updateCommitIndex(conf...
[ "func", "(", "s", "*", "server", ")", "readConf", "(", ")", "error", "{", "confPath", ":=", "path", ".", "Join", "(", "s", ".", "path", ",", "\"", "\"", ")", "\n", "s", ".", "debugln", "(", "\"", "\"", ",", "confPath", ")", "\n\n", "// open conf ...
// Read the configuration for the server.
[ "Read", "the", "configuration", "for", "the", "server", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/server.go#L1437-L1457
25,929
goraft/raft
event.go
newEvent
func newEvent(typ string, value interface{}, prevValue interface{}) *event { return &event{ typ: typ, value: value, prevValue: prevValue, } }
go
func newEvent(typ string, value interface{}, prevValue interface{}) *event { return &event{ typ: typ, value: value, prevValue: prevValue, } }
[ "func", "newEvent", "(", "typ", "string", ",", "value", "interface", "{", "}", ",", "prevValue", "interface", "{", "}", ")", "*", "event", "{", "return", "&", "event", "{", "typ", ":", "typ", ",", "value", ":", "value", ",", "prevValue", ":", "prevVa...
// newEvent creates a new event.
[ "newEvent", "creates", "a", "new", "event", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event.go#L35-L41
25,930
goraft/raft
peer.go
setPrevLogIndex
func (p *Peer) setPrevLogIndex(value uint64) { p.Lock() defer p.Unlock() p.prevLogIndex = value }
go
func (p *Peer) setPrevLogIndex(value uint64) { p.Lock() defer p.Unlock() p.prevLogIndex = value }
[ "func", "(", "p", "*", "Peer", ")", "setPrevLogIndex", "(", "value", "uint64", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "p", ".", "prevLogIndex", "=", "value", "\n", "}" ]
// Sets the previous log index.
[ "Sets", "the", "previous", "log", "index", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/peer.go#L65-L69
25,931
goraft/raft
peer.go
stopHeartbeat
func (p *Peer) stopHeartbeat(flush bool) { p.setLastActivity(time.Time{}) p.stopChan <- flush }
go
func (p *Peer) stopHeartbeat(flush bool) { p.setLastActivity(time.Time{}) p.stopChan <- flush }
[ "func", "(", "p", "*", "Peer", ")", "stopHeartbeat", "(", "flush", "bool", ")", "{", "p", ".", "setLastActivity", "(", "time", ".", "Time", "{", "}", ")", "\n\n", "p", ".", "stopChan", "<-", "flush", "\n", "}" ]
// Stops the peer heartbeat.
[ "Stops", "the", "peer", "heartbeat", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/peer.go#L103-L107
25,932
goraft/raft
peer.go
LastActivity
func (p *Peer) LastActivity() time.Time { p.RLock() defer p.RUnlock() return p.lastActivity }
go
func (p *Peer) LastActivity() time.Time { p.RLock() defer p.RUnlock() return p.lastActivity }
[ "func", "(", "p", "*", "Peer", ")", "LastActivity", "(", ")", "time", ".", "Time", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "return", "p", ".", "lastActivity", "\n", "}" ]
// LastActivity returns the last time any response was received from the peer.
[ "LastActivity", "returns", "the", "last", "time", "any", "response", "was", "received", "from", "the", "peer", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/peer.go#L110-L114
25,933
goraft/raft
peer.go
sendSnapshotRequest
func (p *Peer) sendSnapshotRequest(req *SnapshotRequest) { debugln("peer.snap.send: ", p.Name) resp := p.server.Transporter().SendSnapshotRequest(p.server, p, req) if resp == nil { debugln("peer.snap.timeout: ", p.Name) return } debugln("peer.snap.recv: ", p.Name) // If successful, the peer should have bee...
go
func (p *Peer) sendSnapshotRequest(req *SnapshotRequest) { debugln("peer.snap.send: ", p.Name) resp := p.server.Transporter().SendSnapshotRequest(p.server, p, req) if resp == nil { debugln("peer.snap.timeout: ", p.Name) return } debugln("peer.snap.recv: ", p.Name) // If successful, the peer should have bee...
[ "func", "(", "p", "*", "Peer", ")", "sendSnapshotRequest", "(", "req", "*", "SnapshotRequest", ")", "{", "debugln", "(", "\"", "\"", ",", "p", ".", "Name", ")", "\n\n", "resp", ":=", "p", ".", "server", ".", "Transporter", "(", ")", ".", "SendSnapsho...
// Sends an Snapshot request to the peer through the transport.
[ "Sends", "an", "Snapshot", "request", "to", "the", "peer", "through", "the", "transport", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/peer.go#L258-L280
25,934
goraft/raft
peer.go
sendSnapshotRecoveryRequest
func (p *Peer) sendSnapshotRecoveryRequest() { req := newSnapshotRecoveryRequest(p.server.name, p.server.snapshot) debugln("peer.snap.recovery.send: ", p.Name) resp := p.server.Transporter().SendSnapshotRecoveryRequest(p.server, p, req) if resp == nil { debugln("peer.snap.recovery.timeout: ", p.Name) return }...
go
func (p *Peer) sendSnapshotRecoveryRequest() { req := newSnapshotRecoveryRequest(p.server.name, p.server.snapshot) debugln("peer.snap.recovery.send: ", p.Name) resp := p.server.Transporter().SendSnapshotRecoveryRequest(p.server, p, req) if resp == nil { debugln("peer.snap.recovery.timeout: ", p.Name) return }...
[ "func", "(", "p", "*", "Peer", ")", "sendSnapshotRecoveryRequest", "(", ")", "{", "req", ":=", "newSnapshotRecoveryRequest", "(", "p", ".", "server", ".", "name", ",", "p", ".", "server", ".", "snapshot", ")", "\n", "debugln", "(", "\"", "\"", ",", "p"...
// Sends an Snapshot Recovery request to the peer through the transport.
[ "Sends", "an", "Snapshot", "Recovery", "request", "to", "the", "peer", "through", "the", "transport", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/peer.go#L283-L302
25,935
goraft/raft
debug.go
debugf
func debugf(format string, v ...interface{}) { if logLevel >= Debug { logger.Printf(format, v...) } }
go
func debugf(format string, v ...interface{}) { if logLevel >= Debug { logger.Printf(format, v...) } }
[ "func", "debugf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "logLevel", ">=", "Debug", "{", "logger", ".", "Printf", "(", "format", ",", "v", "...", ")", "\n", "}", "\n", "}" ]
// Prints to the standard logger if debug mode is enabled. Arguments // are handled in the manner of fmt.Printf.
[ "Prints", "to", "the", "standard", "logger", "if", "debug", "mode", "is", "enabled", ".", "Arguments", "are", "handled", "in", "the", "manner", "of", "fmt", ".", "Printf", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/debug.go#L76-L80
25,936
goraft/raft
debug.go
tracef
func tracef(format string, v ...interface{}) { if logLevel >= Trace { logger.Printf(format, v...) } }
go
func tracef(format string, v ...interface{}) { if logLevel >= Trace { logger.Printf(format, v...) } }
[ "func", "tracef", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "logLevel", ">=", "Trace", "{", "logger", ".", "Printf", "(", "format", ",", "v", "...", ")", "\n", "}", "\n", "}" ]
// Prints to the standard logger if trace debugging is enabled. Arguments // are handled in the manner of fmt.Printf.
[ "Prints", "to", "the", "standard", "logger", "if", "trace", "debugging", "is", "enabled", ".", "Arguments", "are", "handled", "in", "the", "manner", "of", "fmt", ".", "Printf", "." ]
0061b6c82526bd96292f41fa72358ec13ee3853c
https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/debug.go#L104-L108
25,937
tebeka/selenium
common.go
filteredURL
func filteredURL(u string) string { // Hide password if set in URL m, err := url.Parse(u) if err != nil { return "" } if m.User != nil { if _, ok := m.User.Password(); ok { m.User = url.UserPassword(m.User.Username(), "__password__") } } return m.String() }
go
func filteredURL(u string) string { // Hide password if set in URL m, err := url.Parse(u) if err != nil { return "" } if m.User != nil { if _, ok := m.User.Password(); ok { m.User = url.UserPassword(m.User.Username(), "__password__") } } return m.String() }
[ "func", "filteredURL", "(", "u", "string", ")", "string", "{", "// Hide password if set in URL", "m", ",", "err", ":=", "url", ".", "Parse", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "m", ".", ...
// filteredURL replaces existing password from the given URL.
[ "filteredURL", "replaces", "existing", "password", "from", "the", "given", "URL", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/common.go#L23-L35
25,938
tebeka/selenium
selenium.go
AddChrome
func (c Capabilities) AddChrome(f chrome.Capabilities) { c[chrome.CapabilitiesKey] = f c[chrome.DeprecatedCapabilitiesKey] = f }
go
func (c Capabilities) AddChrome(f chrome.Capabilities) { c[chrome.CapabilitiesKey] = f c[chrome.DeprecatedCapabilitiesKey] = f }
[ "func", "(", "c", "Capabilities", ")", "AddChrome", "(", "f", "chrome", ".", "Capabilities", ")", "{", "c", "[", "chrome", ".", "CapabilitiesKey", "]", "=", "f", "\n", "c", "[", "chrome", ".", "DeprecatedCapabilitiesKey", "]", "=", "f", "\n", "}" ]
// AddChrome adds Chrome-specific capabilities.
[ "AddChrome", "adds", "Chrome", "-", "specific", "capabilities", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/selenium.go#L96-L99
25,939
tebeka/selenium
selenium.go
AddFirefox
func (c Capabilities) AddFirefox(f firefox.Capabilities) { c[firefox.CapabilitiesKey] = f }
go
func (c Capabilities) AddFirefox(f firefox.Capabilities) { c[firefox.CapabilitiesKey] = f }
[ "func", "(", "c", "Capabilities", ")", "AddFirefox", "(", "f", "firefox", ".", "Capabilities", ")", "{", "c", "[", "firefox", ".", "CapabilitiesKey", "]", "=", "f", "\n", "}" ]
// AddFirefox adds Firefox-specific capabilities.
[ "AddFirefox", "adds", "Firefox", "-", "specific", "capabilities", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/selenium.go#L102-L104
25,940
tebeka/selenium
selenium.go
AddLogging
func (c Capabilities) AddLogging(l log.Capabilities) { c[log.CapabilitiesKey] = l }
go
func (c Capabilities) AddLogging(l log.Capabilities) { c[log.CapabilitiesKey] = l }
[ "func", "(", "c", "Capabilities", ")", "AddLogging", "(", "l", "log", ".", "Capabilities", ")", "{", "c", "[", "log", ".", "CapabilitiesKey", "]", "=", "l", "\n", "}" ]
// AddLogging adds logging configuration to the capabilities.
[ "AddLogging", "adds", "logging", "configuration", "to", "the", "capabilities", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/selenium.go#L112-L114
25,941
tebeka/selenium
selenium.go
SetLogLevel
func (c Capabilities) SetLogLevel(typ log.Type, level log.Level) { if _, ok := c[log.CapabilitiesKey]; !ok { c[log.CapabilitiesKey] = make(log.Capabilities) } m := c[log.CapabilitiesKey].(log.Capabilities) m[typ] = level }
go
func (c Capabilities) SetLogLevel(typ log.Type, level log.Level) { if _, ok := c[log.CapabilitiesKey]; !ok { c[log.CapabilitiesKey] = make(log.Capabilities) } m := c[log.CapabilitiesKey].(log.Capabilities) m[typ] = level }
[ "func", "(", "c", "Capabilities", ")", "SetLogLevel", "(", "typ", "log", ".", "Type", ",", "level", "log", ".", "Level", ")", "{", "if", "_", ",", "ok", ":=", "c", "[", "log", ".", "CapabilitiesKey", "]", ";", "!", "ok", "{", "c", "[", "log", "...
// SetLogLevel sets the logging level of a component. It is a shortcut for // passing a log.Capabilities instance to AddLogging.
[ "SetLogLevel", "sets", "the", "logging", "level", "of", "a", "component", ".", "It", "is", "a", "shortcut", "for", "passing", "a", "log", ".", "Capabilities", "instance", "to", "AddLogging", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/selenium.go#L118-L124
25,942
tebeka/selenium
service.go
Display
func Display(d, xauthPath string) ServiceOption { return func(s *Service) error { if s.display != "" { return fmt.Errorf("service display already set: %v", s.display) } if s.xauthPath != "" { return fmt.Errorf("service xauth path already set: %v", s.xauthPath) } if !isDisplay(d) { return fmt.Errorf(...
go
func Display(d, xauthPath string) ServiceOption { return func(s *Service) error { if s.display != "" { return fmt.Errorf("service display already set: %v", s.display) } if s.xauthPath != "" { return fmt.Errorf("service xauth path already set: %v", s.xauthPath) } if !isDisplay(d) { return fmt.Errorf(...
[ "func", "Display", "(", "d", ",", "xauthPath", "string", ")", "ServiceOption", "{", "return", "func", "(", "s", "*", "Service", ")", "error", "{", "if", "s", ".", "display", "!=", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",...
// Display specifies the value to which set the DISPLAY environment variable, // as well as the path to the Xauthority file containing credentials needed to // write to that X server.
[ "Display", "specifies", "the", "value", "to", "which", "set", "the", "DISPLAY", "environment", "variable", "as", "well", "as", "the", "path", "to", "the", "Xauthority", "file", "containing", "credentials", "needed", "to", "write", "to", "that", "X", "server", ...
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L24-L39
25,943
tebeka/selenium
service.go
isDisplay
func isDisplay(disp string) bool { ds := strings.Split(disp, ".") if len(ds) > 2 { return false } for _, d := range ds { if _, err := strconv.Atoi(d); err != nil { return false } } return true }
go
func isDisplay(disp string) bool { ds := strings.Split(disp, ".") if len(ds) > 2 { return false } for _, d := range ds { if _, err := strconv.Atoi(d); err != nil { return false } } return true }
[ "func", "isDisplay", "(", "disp", "string", ")", "bool", "{", "ds", ":=", "strings", ".", "Split", "(", "disp", ",", "\"", "\"", ")", "\n", "if", "len", "(", "ds", ")", ">", "2", "{", "return", "false", "\n", "}", "\n\n", "for", "_", ",", "d", ...
// isDisplay validates that the given disp is in the format "x" or "x.y", where // x and y are both integers.
[ "isDisplay", "validates", "that", "the", "given", "disp", "is", "in", "the", "format", "x", "or", "x", ".", "y", "where", "x", "and", "y", "are", "both", "integers", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L43-L55
25,944
tebeka/selenium
service.go
StartFrameBufferWithOptions
func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption { return func(s *Service) error { if s.display != "" { return fmt.Errorf("service display already set: %v", s.display) } if s.xauthPath != "" { return fmt.Errorf("service xauth path already set: %v", s.xauthPath) } if s.xvfb != ...
go
func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption { return func(s *Service) error { if s.display != "" { return fmt.Errorf("service display already set: %v", s.display) } if s.xauthPath != "" { return fmt.Errorf("service xauth path already set: %v", s.xauthPath) } if s.xvfb != ...
[ "func", "StartFrameBufferWithOptions", "(", "options", "FrameBufferOptions", ")", "ServiceOption", "{", "return", "func", "(", "s", "*", "Service", ")", "error", "{", "if", "s", ".", "display", "!=", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\...
// StartFrameBufferWithOptions causes an X virtual frame buffer to start before // the WebDriver service. The frame buffer process will be terminated when the // service itself is stopped.
[ "StartFrameBufferWithOptions", "causes", "an", "X", "virtual", "frame", "buffer", "to", "start", "before", "the", "WebDriver", "service", ".", "The", "frame", "buffer", "process", "will", "be", "terminated", "when", "the", "service", "itself", "is", "stopped", "...
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L77-L95
25,945
tebeka/selenium
service.go
Output
func Output(w io.Writer) ServiceOption { return func(s *Service) error { s.output = w return nil } }
go
func Output(w io.Writer) ServiceOption { return func(s *Service) error { s.output = w return nil } }
[ "func", "Output", "(", "w", "io", ".", "Writer", ")", "ServiceOption", "{", "return", "func", "(", "s", "*", "Service", ")", "error", "{", "s", ".", "output", "=", "w", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Output specifies that the WebDriver service should log to the provided // writer.
[ "Output", "specifies", "that", "the", "WebDriver", "service", "should", "log", "to", "the", "provided", "writer", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L99-L104
25,946
tebeka/selenium
service.go
GeckoDriver
func GeckoDriver(path string) ServiceOption { return func(s *Service) error { s.geckoDriverPath = path return nil } }
go
func GeckoDriver(path string) ServiceOption { return func(s *Service) error { s.geckoDriverPath = path return nil } }
[ "func", "GeckoDriver", "(", "path", "string", ")", "ServiceOption", "{", "return", "func", "(", "s", "*", "Service", ")", "error", "{", "s", ".", "geckoDriverPath", "=", "path", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// GeckoDriver sets the path to the geckodriver binary for the Selenium Server. // Unlike other drivers, Selenium Server does not support specifying the // geckodriver path at runtime. This ServiceOption is only useful when calling // NewSeleniumService.
[ "GeckoDriver", "sets", "the", "path", "to", "the", "geckodriver", "binary", "for", "the", "Selenium", "Server", ".", "Unlike", "other", "drivers", "Selenium", "Server", "does", "not", "support", "specifying", "the", "geckodriver", "path", "at", "runtime", ".", ...
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L110-L115
25,947
tebeka/selenium
service.go
JavaPath
func JavaPath(path string) ServiceOption { return func(s *Service) error { s.javaPath = path return nil } }
go
func JavaPath(path string) ServiceOption { return func(s *Service) error { s.javaPath = path return nil } }
[ "func", "JavaPath", "(", "path", "string", ")", "ServiceOption", "{", "return", "func", "(", "s", "*", "Service", ")", "error", "{", "s", ".", "javaPath", "=", "path", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// JavaPath specifies the path to the JRE for a Selenium service.
[ "JavaPath", "specifies", "the", "path", "to", "the", "JRE", "for", "a", "Selenium", "service", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L125-L130
25,948
tebeka/selenium
service.go
NewSeleniumService
func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error) { cmd := exec.Command("java", "-jar", jarPath, "-port", strconv.Itoa(port)) s, err := newService(cmd, "/wd/hub", port, opts...) if err != nil { return nil, err } if s.javaPath != "" { s.cmd.Path = s.javaPath } if s.gec...
go
func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error) { cmd := exec.Command("java", "-jar", jarPath, "-port", strconv.Itoa(port)) s, err := newService(cmd, "/wd/hub", port, opts...) if err != nil { return nil, err } if s.javaPath != "" { s.cmd.Path = s.javaPath } if s.gec...
[ "func", "NewSeleniumService", "(", "jarPath", "string", ",", "port", "int", ",", "opts", "...", "ServiceOption", ")", "(", "*", "Service", ",", "error", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "jarPath", ...
// NewSeleniumService starts a Selenium instance in the background.
[ "NewSeleniumService", "starts", "a", "Selenium", "instance", "in", "the", "background", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L154-L173
25,949
tebeka/selenium
service.go
NewChromeDriverService
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error) { cmd := exec.Command(path, "--port="+strconv.Itoa(port), "--url-base=wd/hub", "--verbose") s, err := newService(cmd, "/wd/hub", port, opts...) if err != nil { return nil, err } s.shutdownURLPath = "/shutdown" if err := ...
go
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error) { cmd := exec.Command(path, "--port="+strconv.Itoa(port), "--url-base=wd/hub", "--verbose") s, err := newService(cmd, "/wd/hub", port, opts...) if err != nil { return nil, err } s.shutdownURLPath = "/shutdown" if err := ...
[ "func", "NewChromeDriverService", "(", "path", "string", ",", "port", "int", ",", "opts", "...", "ServiceOption", ")", "(", "*", "Service", ",", "error", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "path", ",", "\"", "\"", "+", "strconv", ".", ...
// NewChromeDriverService starts a ChromeDriver instance in the background.
[ "NewChromeDriverService", "starts", "a", "ChromeDriver", "instance", "in", "the", "background", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L176-L187
25,950
tebeka/selenium
service.go
Stop
func (s *Service) Stop() error { // Selenium 3 stopped supporting the shutdown URL by default. // https://github.com/SeleniumHQ/selenium/issues/2852 if s.shutdownURLPath == "" { if err := s.cmd.Process.Kill(); err != nil { return err } } else { resp, err := http.Get(s.addr + s.shutdownURLPath) if err != ...
go
func (s *Service) Stop() error { // Selenium 3 stopped supporting the shutdown URL by default. // https://github.com/SeleniumHQ/selenium/issues/2852 if s.shutdownURLPath == "" { if err := s.cmd.Process.Kill(); err != nil { return err } } else { resp, err := http.Get(s.addr + s.shutdownURLPath) if err != ...
[ "func", "(", "s", "*", "Service", ")", "Stop", "(", ")", "error", "{", "// Selenium 3 stopped supporting the shutdown URL by default.", "// https://github.com/SeleniumHQ/selenium/issues/2852", "if", "s", ".", "shutdownURLPath", "==", "\"", "\"", "{", "if", "err", ":=", ...
// Stop shuts down the WebDriver service, and the X virtual frame buffer // if one was started.
[ "Stop", "shuts", "down", "the", "WebDriver", "service", "and", "the", "X", "virtual", "frame", "buffer", "if", "one", "was", "started", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L250-L271
25,951
tebeka/selenium
service.go
NewFrameBufferWithOptions
func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error) { r, w, err := os.Pipe() if err != nil { return nil, err } defer r.Close() auth, err := ioutil.TempFile("", "selenium-xvfb") if err != nil { return nil, err } authPath := auth.Name() if err := auth.Close(); err != nil { ret...
go
func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error) { r, w, err := os.Pipe() if err != nil { return nil, err } defer r.Close() auth, err := ioutil.TempFile("", "selenium-xvfb") if err != nil { return nil, err } authPath := auth.Name() if err := auth.Close(); err != nil { ret...
[ "func", "NewFrameBufferWithOptions", "(", "options", "FrameBufferOptions", ")", "(", "*", "FrameBuffer", ",", "error", ")", "{", "r", ",", "w", ",", "err", ":=", "os", ".", "Pipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", ...
// NewFrameBufferWithOptions starts an X virtual frame buffer running in the background. // FrameBufferOptions may be populated to change the behavior of the frame buffer.
[ "NewFrameBufferWithOptions", "starts", "an", "X", "virtual", "frame", "buffer", "running", "in", "the", "background", ".", "FrameBufferOptions", "may", "be", "populated", "to", "change", "the", "behavior", "of", "the", "frame", "buffer", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L296-L369
25,952
tebeka/selenium
service.go
Stop
func (f FrameBuffer) Stop() error { if err := f.cmd.Process.Kill(); err != nil { return err } os.Remove(f.AuthPath) // best effort removal; ignore error if err := f.cmd.Wait(); err != nil && err.Error() != "signal: killed" { return err } return nil }
go
func (f FrameBuffer) Stop() error { if err := f.cmd.Process.Kill(); err != nil { return err } os.Remove(f.AuthPath) // best effort removal; ignore error if err := f.cmd.Wait(); err != nil && err.Error() != "signal: killed" { return err } return nil }
[ "func", "(", "f", "FrameBuffer", ")", "Stop", "(", ")", "error", "{", "if", "err", ":=", "f", ".", "cmd", ".", "Process", ".", "Kill", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "os", ".", "Remove", "(", "f", "....
// Stop kills the background frame buffer process and removes the X // authorization file.
[ "Stop", "kills", "the", "background", "frame", "buffer", "process", "and", "removes", "the", "X", "authorization", "file", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/service.go#L373-L382
25,953
tebeka/selenium
sauce/connect.go
Start
func (c *Connect) Start() error { c.cmd = exec.Command(c.Path, c.Args...) if c.UserName != "" { c.cmd.Args = append(c.cmd.Args, "--user", c.UserName) } if c.AccessKey != "" { c.cmd.Args = append(c.cmd.Args, "--api-key", c.AccessKey) } if c.SeleniumPort > 0 { c.cmd.Args = append(c.cmd.Args, "--se-port", strc...
go
func (c *Connect) Start() error { c.cmd = exec.Command(c.Path, c.Args...) if c.UserName != "" { c.cmd.Args = append(c.cmd.Args, "--user", c.UserName) } if c.AccessKey != "" { c.cmd.Args = append(c.cmd.Args, "--api-key", c.AccessKey) } if c.SeleniumPort > 0 { c.cmd.Args = append(c.cmd.Args, "--se-port", strc...
[ "func", "(", "c", "*", "Connect", ")", "Start", "(", ")", "error", "{", "c", ".", "cmd", "=", "exec", ".", "Command", "(", "c", ".", "Path", ",", "c", ".", "Args", "...", ")", "\n", "if", "c", ".", "UserName", "!=", "\"", "\"", "{", "c", "....
// Start starts the Sauce Connect Proxy.
[ "Start", "starts", "the", "Sauce", "Connect", "Proxy", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/sauce/connect.go#L47-L121
25,954
tebeka/selenium
sauce/connect.go
Addr
func (c *Connect) Addr() string { return fmt.Sprintf("http://%s:%s@localhost:%d/wd/hub", c.UserName, c.AccessKey, c.SeleniumPort) }
go
func (c *Connect) Addr() string { return fmt.Sprintf("http://%s:%s@localhost:%d/wd/hub", c.UserName, c.AccessKey, c.SeleniumPort) }
[ "func", "(", "c", "*", "Connect", ")", "Addr", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "UserName", ",", "c", ".", "AccessKey", ",", "c", ".", "SeleniumPort", ")", "\n", "}" ]
// Addr returns the URL of the WebDriver endpoint to use for driving the // browser.
[ "Addr", "returns", "the", "URL", "of", "the", "WebDriver", "endpoint", "to", "use", "for", "driving", "the", "browser", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/sauce/connect.go#L125-L127
25,955
tebeka/selenium
chrome/capabilities.go
AddExtension
func (c *Capabilities) AddExtension(path string) error { f, err := os.Open(path) if err != nil { return err } defer f.Close() return c.addExtension(f) }
go
func (c *Capabilities) AddExtension(path string) error { f, err := os.Open(path) if err != nil { return err } defer f.Close() return c.addExtension(f) }
[ "func", "(", "c", "*", "Capabilities", ")", "AddExtension", "(", "path", "string", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f",...
// AddExtension adds an extension for the browser to load at startup. The path // parameter should be a path to an extension file (which typically has a // `.crx` file extension. Note that the contents of the file will be loaded // into memory, as required by the protocol.
[ "AddExtension", "adds", "an", "extension", "for", "the", "browser", "to", "load", "at", "startup", ".", "The", "path", "parameter", "should", "be", "a", "path", "to", "an", "extension", "file", "(", "which", "typically", "has", "a", ".", "crx", "file", "...
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/chrome/capabilities.go#L128-L135
25,956
tebeka/selenium
chrome/capabilities.go
addExtension
func (c *Capabilities) addExtension(r io.Reader) error { var buf bytes.Buffer encoder := base64.NewEncoder(base64.StdEncoding, &buf) if _, err := io.Copy(encoder, bufio.NewReader(r)); err != nil { return err } encoder.Close() c.Extensions = append(c.Extensions, buf.String()) return nil }
go
func (c *Capabilities) addExtension(r io.Reader) error { var buf bytes.Buffer encoder := base64.NewEncoder(base64.StdEncoding, &buf) if _, err := io.Copy(encoder, bufio.NewReader(r)); err != nil { return err } encoder.Close() c.Extensions = append(c.Extensions, buf.String()) return nil }
[ "func", "(", "c", "*", "Capabilities", ")", "addExtension", "(", "r", "io", ".", "Reader", ")", "error", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "encoder", ":=", "base64", ".", "NewEncoder", "(", "base64", ".", "StdEncoding", ",", "&", "buf", ...
// addExtension reads a Chrome extension's data from r, base64-encodes it, and // attaches it to the Capabilities instance.
[ "addExtension", "reads", "a", "Chrome", "extension", "s", "data", "from", "r", "base64", "-", "encodes", "it", "and", "attaches", "it", "to", "the", "Capabilities", "instance", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/chrome/capabilities.go#L139-L148
25,957
tebeka/selenium
chrome/capabilities.go
AddUnpackedExtension
func (c *Capabilities) AddUnpackedExtension(basePath string) error { buf, _, err := NewExtension(basePath) if err != nil { return err } return c.addExtension(bytes.NewBuffer(buf)) }
go
func (c *Capabilities) AddUnpackedExtension(basePath string) error { buf, _, err := NewExtension(basePath) if err != nil { return err } return c.addExtension(bytes.NewBuffer(buf)) }
[ "func", "(", "c", "*", "Capabilities", ")", "AddUnpackedExtension", "(", "basePath", "string", ")", "error", "{", "buf", ",", "_", ",", "err", ":=", "NewExtension", "(", "basePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", ...
// AddUnpackedExtension creates a packaged Chrome extension with the files // below the provided directory path and causes the browser to load that // extension at startup.
[ "AddUnpackedExtension", "creates", "a", "packaged", "Chrome", "extension", "with", "the", "files", "below", "the", "provided", "directory", "path", "and", "causes", "the", "browser", "to", "load", "that", "extension", "at", "startup", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/chrome/capabilities.go#L153-L159
25,958
tebeka/selenium
chrome/capabilities.go
NewExtension
func NewExtension(basePath string) ([]byte, *rsa.PrivateKey, error) { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return nil, nil, err } data, err := NewExtensionWithKey(basePath, key) if err != nil { return nil, nil, err } return data, key, nil }
go
func NewExtension(basePath string) ([]byte, *rsa.PrivateKey, error) { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return nil, nil, err } data, err := NewExtensionWithKey(basePath, key) if err != nil { return nil, nil, err } return data, key, nil }
[ "func", "NewExtension", "(", "basePath", "string", ")", "(", "[", "]", "byte", ",", "*", "rsa", ".", "PrivateKey", ",", "error", ")", "{", "key", ",", "err", ":=", "rsa", ".", "GenerateKey", "(", "rand", ".", "Reader", ",", "2048", ")", "\n", "if",...
// NewExtension creates the payload of a Chrome extension file which is signed // using the returned private key.
[ "NewExtension", "creates", "the", "payload", "of", "a", "Chrome", "extension", "file", "which", "is", "signed", "using", "the", "returned", "private", "key", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/chrome/capabilities.go#L163-L173
25,959
tebeka/selenium
chrome/capabilities.go
NewExtensionWithKey
func NewExtensionWithKey(basePath string, key *rsa.PrivateKey) ([]byte, error) { zip, err := zip.New(basePath) if err != nil { return nil, err } h := sha1.New() if _, err := io.Copy(h, bytes.NewReader(zip.Bytes())); err != nil { return nil, err } hashed := h.Sum(nil) signature, err := rsa.SignPKCS1v15(ran...
go
func NewExtensionWithKey(basePath string, key *rsa.PrivateKey) ([]byte, error) { zip, err := zip.New(basePath) if err != nil { return nil, err } h := sha1.New() if _, err := io.Copy(h, bytes.NewReader(zip.Bytes())); err != nil { return nil, err } hashed := h.Sum(nil) signature, err := rsa.SignPKCS1v15(ran...
[ "func", "NewExtensionWithKey", "(", "basePath", "string", ",", "key", "*", "rsa", ".", "PrivateKey", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "zip", ",", "err", ":=", "zip", ".", "New", "(", "basePath", ")", "\n", "if", "err", "!=", "nil...
// NewExtensionWithKey creates the payload of a Chrome extension file which is // signed by the provided private key.
[ "NewExtensionWithKey", "creates", "the", "payload", "of", "a", "Chrome", "extension", "file", "which", "is", "signed", "by", "the", "provided", "private", "key", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/chrome/capabilities.go#L177-L235
25,960
tebeka/selenium
remote.go
execute
func (wd *remoteWD) execute(method, url string, data []byte) (json.RawMessage, error) { debugLog("-> %s %s\n%s", method, filteredURL(url), data) request, err := newRequest(method, url, data) if err != nil { return nil, err } response, err := HTTPClient.Do(request) if err != nil { return nil, err } buf, er...
go
func (wd *remoteWD) execute(method, url string, data []byte) (json.RawMessage, error) { debugLog("-> %s %s\n%s", method, filteredURL(url), data) request, err := newRequest(method, url, data) if err != nil { return nil, err } response, err := HTTPClient.Do(request) if err != nil { return nil, err } buf, er...
[ "func", "(", "wd", "*", "remoteWD", ")", "execute", "(", "method", ",", "url", "string", ",", "data", "[", "]", "byte", ")", "(", "json", ".", "RawMessage", ",", "error", ")", "{", "debugLog", "(", "\"", "\\n", "\"", ",", "method", ",", "filteredUR...
// execute performs an HTTP request and inspects the returned data for an error // encoded by the remote end in a JSON structure. If no error is present, the // entire, raw request payload is returned.
[ "execute", "performs", "an", "HTTP", "request", "and", "inspects", "the", "returned", "data", "for", "an", "error", "encoded", "by", "the", "remote", "end", "in", "a", "JSON", "structure", ".", "If", "no", "error", "is", "present", "the", "entire", "raw", ...
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/remote.go#L124-L204
25,961
tebeka/selenium
remote.go
parseVersion
func parseVersion(v string) (semver.Version, error) { parts := strings.Split(v, ".") var err error for i := len(parts); i > 0; i-- { var ver semver.Version ver, err = semver.ParseTolerant(strings.Join(parts[:i], ".")) if err == nil { return ver, nil } } return semver.Version{}, err }
go
func parseVersion(v string) (semver.Version, error) { parts := strings.Split(v, ".") var err error for i := len(parts); i > 0; i-- { var ver semver.Version ver, err = semver.ParseTolerant(strings.Join(parts[:i], ".")) if err == nil { return ver, nil } } return semver.Version{}, err }
[ "func", "parseVersion", "(", "v", "string", ")", "(", "semver", ".", "Version", ",", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "v", ",", "\"", "\"", ")", "\n", "var", "err", "error", "\n", "for", "i", ":=", "len", "(", "part...
// parseVersion sanitizes the browser version enough for semver.ParseTolerant // to parse it.
[ "parseVersion", "sanitizes", "the", "browser", "version", "enough", "for", "semver", ".", "ParseTolerant", "to", "parse", "it", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/remote.go#L311-L322
25,962
tebeka/selenium
remote.go
newW3CCapabilities
func newW3CCapabilities(caps Capabilities) Capabilities { alwaysMatch := make(Capabilities) for name, value := range caps { if isValidW3CCapability[name] || strings.Contains(name, ":") { alwaysMatch[name] = value } } // Move the Firefox profile setting from the old location to the new // location. if prof...
go
func newW3CCapabilities(caps Capabilities) Capabilities { alwaysMatch := make(Capabilities) for name, value := range caps { if isValidW3CCapability[name] || strings.Contains(name, ":") { alwaysMatch[name] = value } } // Move the Firefox profile setting from the old location to the new // location. if prof...
[ "func", "newW3CCapabilities", "(", "caps", "Capabilities", ")", "Capabilities", "{", "alwaysMatch", ":=", "make", "(", "Capabilities", ")", "\n", "for", "name", ",", "value", ":=", "range", "caps", "{", "if", "isValidW3CCapability", "[", "name", "]", "||", "...
// Create a W3C-compatible capabilities instance.
[ "Create", "a", "W3C", "-", "compatible", "capabilities", "instance", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/remote.go#L350-L376
25,963
tebeka/selenium
remote.go
rect
func (elem *remoteWE) rect() (*rect, error) { wd := elem.parent url := wd.requestURL("/session/%s/element/%s/rect", wd.id, elem.id) response, err := wd.execute("GET", url, nil) if err != nil { return nil, err } r := new(struct{ Value rect }) if err := json.Unmarshal(response, r); err != nil { return nil, err...
go
func (elem *remoteWE) rect() (*rect, error) { wd := elem.parent url := wd.requestURL("/session/%s/element/%s/rect", wd.id, elem.id) response, err := wd.execute("GET", url, nil) if err != nil { return nil, err } r := new(struct{ Value rect }) if err := json.Unmarshal(response, r); err != nil { return nil, err...
[ "func", "(", "elem", "*", "remoteWE", ")", "rect", "(", ")", "(", "*", "rect", ",", "error", ")", "{", "wd", ":=", "elem", ".", "parent", "\n", "url", ":=", "wd", ".", "requestURL", "(", "\"", "\"", ",", "wd", ".", "id", ",", "elem", ".", "id...
// rect implements the "Get Element Rect" method of the W3C standard.
[ "rect", "implements", "the", "Get", "Element", "Rect", "method", "of", "the", "W3C", "standard", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/remote.go#L1416-L1428
25,964
tebeka/selenium
internal/zip/zip.go
New
func New(basePath string) (*bytes.Buffer, error) { fi, err := os.Stat(basePath) if err != nil { return nil, err } if !fi.IsDir() { return nil, fmt.Errorf("path %q is not a directory, which is required for a Firefox profile", basePath) } buf := new(bytes.Buffer) w := zip.NewWriter(buf) err = filepath.Walk(b...
go
func New(basePath string) (*bytes.Buffer, error) { fi, err := os.Stat(basePath) if err != nil { return nil, err } if !fi.IsDir() { return nil, fmt.Errorf("path %q is not a directory, which is required for a Firefox profile", basePath) } buf := new(bytes.Buffer) w := zip.NewWriter(buf) err = filepath.Walk(b...
[ "func", "New", "(", "basePath", "string", ")", "(", "*", "bytes", ".", "Buffer", ",", "error", ")", "{", "fi", ",", "err", ":=", "os", ".", "Stat", "(", "basePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}...
// New returns a buffer that contains the payload of a Zip file.
[ "New", "returns", "a", "buffer", "that", "contains", "the", "payload", "of", "a", "Zip", "file", "." ]
edf31bb7fd715ad505d9190f8d65d13f39a7c825
https://github.com/tebeka/selenium/blob/edf31bb7fd715ad505d9190f8d65d13f39a7c825/internal/zip/zip.go#L15-L68
25,965
cheggaaa/pb
pool.go
NewPool
func NewPool(pbs ...*ProgressBar) (pool *Pool) { pool = new(Pool) pool.Add(pbs...) return }
go
func NewPool(pbs ...*ProgressBar) (pool *Pool) { pool = new(Pool) pool.Add(pbs...) return }
[ "func", "NewPool", "(", "pbs", "...", "*", "ProgressBar", ")", "(", "pool", "*", "Pool", ")", "{", "pool", "=", "new", "(", "Pool", ")", "\n", "pool", ".", "Add", "(", "pbs", "...", ")", "\n", "return", "\n", "}" ]
// NewPool initialises a pool with progress bars, but // doesn't start it. You need to call Start manually
[ "NewPool", "initialises", "a", "pool", "with", "progress", "bars", "but", "doesn", "t", "start", "it", ".", "You", "need", "to", "call", "Start", "manually" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pool.go#L24-L28
25,966
cheggaaa/pb
pool.go
Add
func (p *Pool) Add(pbs ...*ProgressBar) { p.m.Lock() defer p.m.Unlock() for _, bar := range pbs { bar.ManualUpdate = true bar.NotPrint = true bar.Start() p.bars = append(p.bars, bar) } }
go
func (p *Pool) Add(pbs ...*ProgressBar) { p.m.Lock() defer p.m.Unlock() for _, bar := range pbs { bar.ManualUpdate = true bar.NotPrint = true bar.Start() p.bars = append(p.bars, bar) } }
[ "func", "(", "p", "*", "Pool", ")", "Add", "(", "pbs", "...", "*", "ProgressBar", ")", "{", "p", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "m", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "bar", ":=", "range", "pbs", "{"...
// Add progress bars.
[ "Add", "progress", "bars", "." ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pool.go#L42-L51
25,967
cheggaaa/pb
pool.go
Stop
func (p *Pool) Stop() error { p.finishOnce.Do(func() { if p.shutdownCh != nil { close(p.shutdownCh) } }) // Wait for the worker to complete select { case <-p.workerCh: } return unlockEcho() }
go
func (p *Pool) Stop() error { p.finishOnce.Do(func() { if p.shutdownCh != nil { close(p.shutdownCh) } }) // Wait for the worker to complete select { case <-p.workerCh: } return unlockEcho() }
[ "func", "(", "p", "*", "Pool", ")", "Stop", "(", ")", "error", "{", "p", ".", "finishOnce", ".", "Do", "(", "func", "(", ")", "{", "if", "p", ".", "shutdownCh", "!=", "nil", "{", "close", "(", "p", ".", "shutdownCh", ")", "\n", "}", "\n", "}"...
// Restore terminal state and close pool
[ "Restore", "terminal", "state", "and", "close", "pool" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pool.go#L91-L104
25,968
cheggaaa/pb
format.go
formatBytes
func formatBytes(i int64) (result string) { switch { case i >= TiB: result = fmt.Sprintf("%.02f TiB", float64(i)/TiB) case i >= GiB: result = fmt.Sprintf("%.02f GiB", float64(i)/GiB) case i >= MiB: result = fmt.Sprintf("%.02f MiB", float64(i)/MiB) case i >= KiB: result = fmt.Sprintf("%.02f KiB", float64(i)...
go
func formatBytes(i int64) (result string) { switch { case i >= TiB: result = fmt.Sprintf("%.02f TiB", float64(i)/TiB) case i >= GiB: result = fmt.Sprintf("%.02f GiB", float64(i)/GiB) case i >= MiB: result = fmt.Sprintf("%.02f MiB", float64(i)/MiB) case i >= KiB: result = fmt.Sprintf("%.02f KiB", float64(i)...
[ "func", "formatBytes", "(", "i", "int64", ")", "(", "result", "string", ")", "{", "switch", "{", "case", "i", ">=", "TiB", ":", "result", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "i", ")", "/", "TiB", ")", "\n", "case", ...
// Convert bytes to human readable string. Like 2 MiB, 64.2 KiB, 52 B
[ "Convert", "bytes", "to", "human", "readable", "string", ".", "Like", "2", "MiB", "64", ".", "2", "KiB", "52", "B" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/format.go#L77-L91
25,969
cheggaaa/pb
format.go
formatBytesDec
func formatBytesDec(i int64) (result string) { switch { case i >= TB: result = fmt.Sprintf("%.02f TB", float64(i)/TB) case i >= GB: result = fmt.Sprintf("%.02f GB", float64(i)/GB) case i >= MB: result = fmt.Sprintf("%.02f MB", float64(i)/MB) case i >= KB: result = fmt.Sprintf("%.02f KB", float64(i)/KB) de...
go
func formatBytesDec(i int64) (result string) { switch { case i >= TB: result = fmt.Sprintf("%.02f TB", float64(i)/TB) case i >= GB: result = fmt.Sprintf("%.02f GB", float64(i)/GB) case i >= MB: result = fmt.Sprintf("%.02f MB", float64(i)/MB) case i >= KB: result = fmt.Sprintf("%.02f KB", float64(i)/KB) de...
[ "func", "formatBytesDec", "(", "i", "int64", ")", "(", "result", "string", ")", "{", "switch", "{", "case", "i", ">=", "TB", ":", "result", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "i", ")", "/", "TB", ")", "\n", "case", ...
// Convert bytes to base-10 human readable string. Like 2 MB, 64.2 KB, 52 B
[ "Convert", "bytes", "to", "base", "-", "10", "human", "readable", "string", ".", "Like", "2", "MB", "64", ".", "2", "KB", "52", "B" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/format.go#L94-L108
25,970
cheggaaa/pb
pb.go
Get
func (pb *ProgressBar) Get() int64 { c := atomic.LoadInt64(&pb.current) return c }
go
func (pb *ProgressBar) Get() int64 { c := atomic.LoadInt64(&pb.current) return c }
[ "func", "(", "pb", "*", "ProgressBar", ")", "Get", "(", ")", "int64", "{", "c", ":=", "atomic", ".", "LoadInt64", "(", "&", "pb", ".", "current", ")", "\n", "return", "c", "\n", "}" ]
// Get current value
[ "Get", "current", "value" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L135-L138
25,971
cheggaaa/pb
pb.go
Set
func (pb *ProgressBar) Set(current int) *ProgressBar { return pb.Set64(int64(current)) }
go
func (pb *ProgressBar) Set(current int) *ProgressBar { return pb.Set64(int64(current)) }
[ "func", "(", "pb", "*", "ProgressBar", ")", "Set", "(", "current", "int", ")", "*", "ProgressBar", "{", "return", "pb", ".", "Set64", "(", "int64", "(", "current", ")", ")", "\n", "}" ]
// Set current value
[ "Set", "current", "value" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L141-L143
25,972
cheggaaa/pb
pb.go
Add
func (pb *ProgressBar) Add(add int) int { return int(pb.Add64(int64(add))) }
go
func (pb *ProgressBar) Add(add int) int { return int(pb.Add64(int64(add))) }
[ "func", "(", "pb", "*", "ProgressBar", ")", "Add", "(", "add", "int", ")", "int", "{", "return", "int", "(", "pb", ".", "Add64", "(", "int64", "(", "add", ")", ")", ")", "\n", "}" ]
// Add to current value
[ "Add", "to", "current", "value" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L152-L154
25,973
cheggaaa/pb
pb.go
IsFinished
func (pb *ProgressBar) IsFinished() bool { pb.mu.Lock() defer pb.mu.Unlock() return pb.isFinish }
go
func (pb *ProgressBar) IsFinished() bool { pb.mu.Lock() defer pb.mu.Unlock() return pb.isFinish }
[ "func", "(", "pb", "*", "ProgressBar", ")", "IsFinished", "(", ")", "bool", "{", "pb", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "pb", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "pb", ".", "isFinish", "\n", "}" ]
// IsFinished return boolean
[ "IsFinished", "return", "boolean" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L243-L247
25,974
cheggaaa/pb
pb.go
FinishPrint
func (pb *ProgressBar) FinishPrint(str string) { pb.Finish() if pb.Output != nil { fmt.Fprintln(pb.Output, str) } else { fmt.Println(str) } }
go
func (pb *ProgressBar) FinishPrint(str string) { pb.Finish() if pb.Output != nil { fmt.Fprintln(pb.Output, str) } else { fmt.Println(str) } }
[ "func", "(", "pb", "*", "ProgressBar", ")", "FinishPrint", "(", "str", "string", ")", "{", "pb", ".", "Finish", "(", ")", "\n", "if", "pb", ".", "Output", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "pb", ".", "Output", ",", "str", ")", "\n", ...
// End print and write string 'str'
[ "End", "print", "and", "write", "string", "str" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L250-L257
25,975
cheggaaa/pb
pb.go
Write
func (pb *ProgressBar) Write(p []byte) (n int, err error) { n = len(p) pb.Add(n) return }
go
func (pb *ProgressBar) Write(p []byte) (n int, err error) { n = len(p) pb.Add(n) return }
[ "func", "(", "pb", "*", "ProgressBar", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "n", "=", "len", "(", "p", ")", "\n", "pb", ".", "Add", "(", "n", ")", "\n", "return", "\n", "}" ]
// implement io.Writer
[ "implement", "io", ".", "Writer" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L260-L264
25,976
cheggaaa/pb
pb.go
NewProxyReader
func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader { return &Reader{r, pb} }
go
func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader { return &Reader{r, pb} }
[ "func", "(", "pb", "*", "ProgressBar", ")", "NewProxyReader", "(", "r", "io", ".", "Reader", ")", "*", "Reader", "{", "return", "&", "Reader", "{", "r", ",", "pb", "}", "\n", "}" ]
// Create new proxy reader over bar // Takes io.Reader or io.ReadCloser
[ "Create", "new", "proxy", "reader", "over", "bar", "Takes", "io", ".", "Reader", "or", "io", ".", "ReadCloser" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L275-L277
25,977
cheggaaa/pb
pb.go
String
func (pb *ProgressBar) String() string { pb.mu.Lock() defer pb.mu.Unlock() return pb.lastPrint }
go
func (pb *ProgressBar) String() string { pb.mu.Lock() defer pb.mu.Unlock() return pb.lastPrint }
[ "func", "(", "pb", "*", "ProgressBar", ")", "String", "(", ")", "string", "{", "pb", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "pb", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "pb", ".", "lastPrint", "\n", "}" ]
// String return the last bar print
[ "String", "return", "the", "last", "bar", "print" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L461-L465
25,978
cheggaaa/pb
pb.go
SetTotal
func (pb *ProgressBar) SetTotal(total int) *ProgressBar { return pb.SetTotal64(int64(total)) }
go
func (pb *ProgressBar) SetTotal(total int) *ProgressBar { return pb.SetTotal64(int64(total)) }
[ "func", "(", "pb", "*", "ProgressBar", ")", "SetTotal", "(", "total", "int", ")", "*", "ProgressBar", "{", "return", "pb", ".", "SetTotal64", "(", "int64", "(", "total", ")", ")", "\n", "}" ]
// SetTotal atomically sets new total count
[ "SetTotal", "atomically", "sets", "new", "total", "count" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L468-L470
25,979
cheggaaa/pb
pb.go
SetTotal64
func (pb *ProgressBar) SetTotal64(total int64) *ProgressBar { atomic.StoreInt64(&pb.Total, total) return pb }
go
func (pb *ProgressBar) SetTotal64(total int64) *ProgressBar { atomic.StoreInt64(&pb.Total, total) return pb }
[ "func", "(", "pb", "*", "ProgressBar", ")", "SetTotal64", "(", "total", "int64", ")", "*", "ProgressBar", "{", "atomic", ".", "StoreInt64", "(", "&", "pb", ".", "Total", ",", "total", ")", "\n", "return", "pb", "\n", "}" ]
// SetTotal64 atomically sets new total count
[ "SetTotal64", "atomically", "sets", "new", "total", "count" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L473-L476
25,980
cheggaaa/pb
pb.go
Reset
func (pb *ProgressBar) Reset(total int) *ProgressBar { pb.mu.Lock() defer pb.mu.Unlock() if pb.isFinish { pb.SetTotal(total).Set(0) atomic.StoreInt64(&pb.previous, 0) } return pb }
go
func (pb *ProgressBar) Reset(total int) *ProgressBar { pb.mu.Lock() defer pb.mu.Unlock() if pb.isFinish { pb.SetTotal(total).Set(0) atomic.StoreInt64(&pb.previous, 0) } return pb }
[ "func", "(", "pb", "*", "ProgressBar", ")", "Reset", "(", "total", "int", ")", "*", "ProgressBar", "{", "pb", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "pb", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "pb", ".", "isFinish", "{", "pb...
// Reset bar and set new total count // Does effect only on finished bar
[ "Reset", "bar", "and", "set", "new", "total", "count", "Does", "effect", "only", "on", "finished", "bar" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L480-L488
25,981
cheggaaa/pb
pb.go
refresher
func (pb *ProgressBar) refresher() { for { select { case <-pb.finish: return case <-time.After(pb.RefreshRate): pb.Update() } } }
go
func (pb *ProgressBar) refresher() { for { select { case <-pb.finish: return case <-time.After(pb.RefreshRate): pb.Update() } } }
[ "func", "(", "pb", "*", "ProgressBar", ")", "refresher", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "pb", ".", "finish", ":", "return", "\n", "case", "<-", "time", ".", "After", "(", "pb", ".", "RefreshRate", ")", ":", "pb", ".", "Up...
// Internal loop for refreshing the progressbar
[ "Internal", "loop", "for", "refreshing", "the", "progressbar" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb.go#L491-L500
25,982
cheggaaa/pb
pb_x.go
catchTerminate
func catchTerminate(shutdownCh chan struct{}) { sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL) defer signal.Stop(sig) select { case <-shutdownCh: unlockEcho() case <-sig: unlockEcho() } }
go
func catchTerminate(shutdownCh chan struct{}) { sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL) defer signal.Stop(sig) select { case <-shutdownCh: unlockEcho() case <-sig: unlockEcho() } }
[ "func", "catchTerminate", "(", "shutdownCh", "chan", "struct", "{", "}", ")", "{", "sig", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "1", ")", "\n", "signal", ".", "Notify", "(", "sig", ",", "os", ".", "Interrupt", ",", "syscall", ".", "S...
// listen exit signals and restore terminal state
[ "listen", "exit", "signals", "and", "restore", "terminal", "state" ]
f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11
https://github.com/cheggaaa/pb/blob/f907f6f5dd81f77c2bbc1cde92e4c5a04720cb11/pb_x.go#L108-L118
25,983
coocood/freecache
iterator.go
Next
func (it *Iterator) Next() *Entry { for it.segmentIdx < 256 { entry := it.nextForSegment(it.segmentIdx) if entry != nil { return entry } it.segmentIdx++ it.slotIdx = 0 it.entryIdx = 0 } return nil }
go
func (it *Iterator) Next() *Entry { for it.segmentIdx < 256 { entry := it.nextForSegment(it.segmentIdx) if entry != nil { return entry } it.segmentIdx++ it.slotIdx = 0 it.entryIdx = 0 } return nil }
[ "func", "(", "it", "*", "Iterator", ")", "Next", "(", ")", "*", "Entry", "{", "for", "it", ".", "segmentIdx", "<", "256", "{", "entry", ":=", "it", ".", "nextForSegment", "(", "it", ".", "segmentIdx", ")", "\n", "if", "entry", "!=", "nil", "{", "...
// Next returns the next entry for the iterator. // The order of the entries is not guaranteed. // If there is no more entries to return, nil will be returned.
[ "Next", "returns", "the", "next", "entry", "for", "the", "iterator", ".", "The", "order", "of", "the", "entries", "is", "not", "guaranteed", ".", "If", "there", "is", "no", "more", "entries", "to", "return", "nil", "will", "be", "returned", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/iterator.go#L25-L36
25,984
coocood/freecache
cache.go
Get
func (cache *Cache) Get(key []byte) (value []byte, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() value, _, err = cache.segments[segID].get(key, nil, hashVal) cache.locks[segID].Unlock() return }
go
func (cache *Cache) Get(key []byte) (value []byte, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() value, _, err = cache.segments[segID].get(key, nil, hashVal) cache.locks[segID].Unlock() return }
[ "func", "(", "cache", "*", "Cache", ")", "Get", "(", "key", "[", "]", "byte", ")", "(", "value", "[", "]", "byte", ",", "err", "error", ")", "{", "hashVal", ":=", "hashFunc", "(", "key", ")", "\n", "segID", ":=", "hashVal", "&", "segmentAndOpVal", ...
// Get returns the value or not found error.
[ "Get", "returns", "the", "value", "or", "not", "found", "error", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L59-L66
25,985
coocood/freecache
cache.go
GetWithExpiration
func (cache *Cache) GetWithExpiration(key []byte) (value []byte, expireAt uint32, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() value, expireAt, err = cache.segments[segID].get(key, nil, hashVal) cache.locks[segID].Unlock() return }
go
func (cache *Cache) GetWithExpiration(key []byte) (value []byte, expireAt uint32, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() value, expireAt, err = cache.segments[segID].get(key, nil, hashVal) cache.locks[segID].Unlock() return }
[ "func", "(", "cache", "*", "Cache", ")", "GetWithExpiration", "(", "key", "[", "]", "byte", ")", "(", "value", "[", "]", "byte", ",", "expireAt", "uint32", ",", "err", "error", ")", "{", "hashVal", ":=", "hashFunc", "(", "key", ")", "\n", "segID", ...
// GetWithExpiration returns the value with expiration or not found error.
[ "GetWithExpiration", "returns", "the", "value", "with", "expiration", "or", "not", "found", "error", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L80-L87
25,986
coocood/freecache
cache.go
TTL
func (cache *Cache) TTL(key []byte) (timeLeft uint32, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() timeLeft, err = cache.segments[segID].ttl(key, hashVal) cache.locks[segID].Unlock() return }
go
func (cache *Cache) TTL(key []byte) (timeLeft uint32, err error) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() timeLeft, err = cache.segments[segID].ttl(key, hashVal) cache.locks[segID].Unlock() return }
[ "func", "(", "cache", "*", "Cache", ")", "TTL", "(", "key", "[", "]", "byte", ")", "(", "timeLeft", "uint32", ",", "err", "error", ")", "{", "hashVal", ":=", "hashFunc", "(", "key", ")", "\n", "segID", ":=", "hashVal", "&", "segmentAndOpVal", "\n", ...
// TTL returns the TTL time left for a given key or a not found error.
[ "TTL", "returns", "the", "TTL", "time", "left", "for", "a", "given", "key", "or", "a", "not", "found", "error", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L90-L97
25,987
coocood/freecache
cache.go
Del
func (cache *Cache) Del(key []byte) (affected bool) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() affected = cache.segments[segID].del(key, hashVal) cache.locks[segID].Unlock() return }
go
func (cache *Cache) Del(key []byte) (affected bool) { hashVal := hashFunc(key) segID := hashVal & segmentAndOpVal cache.locks[segID].Lock() affected = cache.segments[segID].del(key, hashVal) cache.locks[segID].Unlock() return }
[ "func", "(", "cache", "*", "Cache", ")", "Del", "(", "key", "[", "]", "byte", ")", "(", "affected", "bool", ")", "{", "hashVal", ":=", "hashFunc", "(", "key", ")", "\n", "segID", ":=", "hashVal", "&", "segmentAndOpVal", "\n", "cache", ".", "locks", ...
// Del deletes an item in the cache by key and returns true or false if a delete occurred.
[ "Del", "deletes", "an", "item", "in", "the", "cache", "by", "key", "and", "returns", "true", "or", "false", "if", "a", "delete", "occurred", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L100-L107
25,988
coocood/freecache
cache.go
SetInt
func (cache *Cache) SetInt(key int64, value []byte, expireSeconds int) (err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Set(bKey[:], value, expireSeconds) }
go
func (cache *Cache) SetInt(key int64, value []byte, expireSeconds int) (err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Set(bKey[:], value, expireSeconds) }
[ "func", "(", "cache", "*", "Cache", ")", "SetInt", "(", "key", "int64", ",", "value", "[", "]", "byte", ",", "expireSeconds", "int", ")", "(", "err", "error", ")", "{", "var", "bKey", "[", "8", "]", "byte", "\n", "binary", ".", "LittleEndian", ".",...
// SetInt stores in integer value in the cache.
[ "SetInt", "stores", "in", "integer", "value", "in", "the", "cache", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L110-L114
25,989
coocood/freecache
cache.go
GetInt
func (cache *Cache) GetInt(key int64) (value []byte, err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Get(bKey[:]) }
go
func (cache *Cache) GetInt(key int64) (value []byte, err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Get(bKey[:]) }
[ "func", "(", "cache", "*", "Cache", ")", "GetInt", "(", "key", "int64", ")", "(", "value", "[", "]", "byte", ",", "err", "error", ")", "{", "var", "bKey", "[", "8", "]", "byte", "\n", "binary", ".", "LittleEndian", ".", "PutUint64", "(", "bKey", ...
// GetInt returns the value for an integer within the cache or a not found error.
[ "GetInt", "returns", "the", "value", "for", "an", "integer", "within", "the", "cache", "or", "a", "not", "found", "error", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L117-L121
25,990
coocood/freecache
cache.go
GetIntWithExpiration
func (cache *Cache) GetIntWithExpiration(key int64) (value []byte, expireAt uint32, err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.GetWithExpiration(bKey[:]) }
go
func (cache *Cache) GetIntWithExpiration(key int64) (value []byte, expireAt uint32, err error) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.GetWithExpiration(bKey[:]) }
[ "func", "(", "cache", "*", "Cache", ")", "GetIntWithExpiration", "(", "key", "int64", ")", "(", "value", "[", "]", "byte", ",", "expireAt", "uint32", ",", "err", "error", ")", "{", "var", "bKey", "[", "8", "]", "byte", "\n", "binary", ".", "LittleEnd...
// GetIntWithExpiration returns the value and expiration or a not found error.
[ "GetIntWithExpiration", "returns", "the", "value", "and", "expiration", "or", "a", "not", "found", "error", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L124-L128
25,991
coocood/freecache
cache.go
DelInt
func (cache *Cache) DelInt(key int64) (affected bool) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Del(bKey[:]) }
go
func (cache *Cache) DelInt(key int64) (affected bool) { var bKey [8]byte binary.LittleEndian.PutUint64(bKey[:], uint64(key)) return cache.Del(bKey[:]) }
[ "func", "(", "cache", "*", "Cache", ")", "DelInt", "(", "key", "int64", ")", "(", "affected", "bool", ")", "{", "var", "bKey", "[", "8", "]", "byte", "\n", "binary", ".", "LittleEndian", ".", "PutUint64", "(", "bKey", "[", ":", "]", ",", "uint64", ...
// DelInt deletes an item in the cache by int key and returns true or false if a delete occurred.
[ "DelInt", "deletes", "an", "item", "in", "the", "cache", "by", "int", "key", "and", "returns", "true", "or", "false", "if", "a", "delete", "occurred", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L131-L135
25,992
coocood/freecache
cache.go
EvacuateCount
func (cache *Cache) EvacuateCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].totalEvacuate) } return }
go
func (cache *Cache) EvacuateCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].totalEvacuate) } return }
[ "func", "(", "cache", "*", "Cache", ")", "EvacuateCount", "(", ")", "(", "count", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "count", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments", "[", "i", ...
// EvacuateCount is a metric indicating the number of times an eviction occurred.
[ "EvacuateCount", "is", "a", "metric", "indicating", "the", "number", "of", "times", "an", "eviction", "occurred", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L138-L143
25,993
coocood/freecache
cache.go
ExpiredCount
func (cache *Cache) ExpiredCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].totalExpired) } return }
go
func (cache *Cache) ExpiredCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].totalExpired) } return }
[ "func", "(", "cache", "*", "Cache", ")", "ExpiredCount", "(", ")", "(", "count", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "count", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments", "[", "i", "...
// ExpiredCount is a metric indicating the number of times an expire occurred.
[ "ExpiredCount", "is", "a", "metric", "indicating", "the", "number", "of", "times", "an", "expire", "occurred", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L146-L151
25,994
coocood/freecache
cache.go
EntryCount
func (cache *Cache) EntryCount() (entryCount int64) { for i := range cache.segments { entryCount += atomic.LoadInt64(&cache.segments[i].entryCount) } return }
go
func (cache *Cache) EntryCount() (entryCount int64) { for i := range cache.segments { entryCount += atomic.LoadInt64(&cache.segments[i].entryCount) } return }
[ "func", "(", "cache", "*", "Cache", ")", "EntryCount", "(", ")", "(", "entryCount", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "entryCount", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments", "[", ...
// EntryCount returns the number of items currently in the cache.
[ "EntryCount", "returns", "the", "number", "of", "items", "currently", "in", "the", "cache", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L154-L159
25,995
coocood/freecache
cache.go
AverageAccessTime
func (cache *Cache) AverageAccessTime() int64 { var entryCount, totalTime int64 for i := range cache.segments { totalTime += atomic.LoadInt64(&cache.segments[i].totalTime) entryCount += atomic.LoadInt64(&cache.segments[i].totalCount) } if entryCount == 0 { return 0 } else { return totalTime / entryCount }...
go
func (cache *Cache) AverageAccessTime() int64 { var entryCount, totalTime int64 for i := range cache.segments { totalTime += atomic.LoadInt64(&cache.segments[i].totalTime) entryCount += atomic.LoadInt64(&cache.segments[i].totalCount) } if entryCount == 0 { return 0 } else { return totalTime / entryCount }...
[ "func", "(", "cache", "*", "Cache", ")", "AverageAccessTime", "(", ")", "int64", "{", "var", "entryCount", ",", "totalTime", "int64", "\n", "for", "i", ":=", "range", "cache", ".", "segments", "{", "totalTime", "+=", "atomic", ".", "LoadInt64", "(", "&",...
// AverageAccessTime returns the average unix timestamp when a entry being accessed. // Entries have greater access time will be evacuated when it // is about to be overwritten by new value.
[ "AverageAccessTime", "returns", "the", "average", "unix", "timestamp", "when", "a", "entry", "being", "accessed", ".", "Entries", "have", "greater", "access", "time", "will", "be", "evacuated", "when", "it", "is", "about", "to", "be", "overwritten", "by", "new...
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L164-L175
25,996
coocood/freecache
cache.go
HitCount
func (cache *Cache) HitCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].hitCount) } return }
go
func (cache *Cache) HitCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].hitCount) } return }
[ "func", "(", "cache", "*", "Cache", ")", "HitCount", "(", ")", "(", "count", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "count", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments", "[", "i", "]", ...
// HitCount is a metric that returns number of times a key was found in the cache.
[ "HitCount", "is", "a", "metric", "that", "returns", "number", "of", "times", "a", "key", "was", "found", "in", "the", "cache", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L178-L183
25,997
coocood/freecache
cache.go
MissCount
func (cache *Cache) MissCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].missCount) } return }
go
func (cache *Cache) MissCount() (count int64) { for i := range cache.segments { count += atomic.LoadInt64(&cache.segments[i].missCount) } return }
[ "func", "(", "cache", "*", "Cache", ")", "MissCount", "(", ")", "(", "count", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "count", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments", "[", "i", "]",...
// MissCount is a metric that returns the number of times a miss occurred in the cache.
[ "MissCount", "is", "a", "metric", "that", "returns", "the", "number", "of", "times", "a", "miss", "occurred", "in", "the", "cache", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L186-L191
25,998
coocood/freecache
cache.go
HitRate
func (cache *Cache) HitRate() float64 { hitCount, missCount := cache.HitCount(), cache.MissCount() lookupCount := hitCount + missCount if lookupCount == 0 { return 0 } else { return float64(hitCount) / float64(lookupCount) } }
go
func (cache *Cache) HitRate() float64 { hitCount, missCount := cache.HitCount(), cache.MissCount() lookupCount := hitCount + missCount if lookupCount == 0 { return 0 } else { return float64(hitCount) / float64(lookupCount) } }
[ "func", "(", "cache", "*", "Cache", ")", "HitRate", "(", ")", "float64", "{", "hitCount", ",", "missCount", ":=", "cache", ".", "HitCount", "(", ")", ",", "cache", ".", "MissCount", "(", ")", "\n", "lookupCount", ":=", "hitCount", "+", "missCount", "\n...
// HitRate is the ratio of hits over lookups.
[ "HitRate", "is", "the", "ratio", "of", "hits", "over", "lookups", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L199-L207
25,999
coocood/freecache
cache.go
OverwriteCount
func (cache *Cache) OverwriteCount() (overwriteCount int64) { for i := range cache.segments { overwriteCount += atomic.LoadInt64(&cache.segments[i].overwrites) } return }
go
func (cache *Cache) OverwriteCount() (overwriteCount int64) { for i := range cache.segments { overwriteCount += atomic.LoadInt64(&cache.segments[i].overwrites) } return }
[ "func", "(", "cache", "*", "Cache", ")", "OverwriteCount", "(", ")", "(", "overwriteCount", "int64", ")", "{", "for", "i", ":=", "range", "cache", ".", "segments", "{", "overwriteCount", "+=", "atomic", ".", "LoadInt64", "(", "&", "cache", ".", "segments...
// OverwriteCount indicates the number of times entries have been overriden.
[ "OverwriteCount", "indicates", "the", "number", "of", "times", "entries", "have", "been", "overriden", "." ]
142b9e1225b0ecdbe420d8fe6cef33f268670c42
https://github.com/coocood/freecache/blob/142b9e1225b0ecdbe420d8fe6cef33f268670c42/cache.go#L210-L215