repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
docker/swarmkit
manager/state/store/memory.go
Wedged
func (s *MemoryStore) Wedged() bool { lockedAt := s.updateLock.LockedAt() if lockedAt.IsZero() { return false } return time.Since(lockedAt) > WedgeTimeout }
go
func (s *MemoryStore) Wedged() bool { lockedAt := s.updateLock.LockedAt() if lockedAt.IsZero() { return false } return time.Since(lockedAt) > WedgeTimeout }
[ "func", "(", "s", "*", "MemoryStore", ")", "Wedged", "(", ")", "bool", "{", "lockedAt", ":=", "s", ".", "updateLock", ".", "LockedAt", "(", ")", "\n", "if", "lockedAt", ".", "IsZero", "(", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "...
// Wedged returns true if the store lock has been held for a long time, // possibly indicating a deadlock.
[ "Wedged", "returns", "true", "if", "the", "store", "lock", "has", "been", "held", "for", "a", "long", "time", "possibly", "indicating", "a", "deadlock", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L972-L979
train
docker/swarmkit
template/getter.go
NewTemplatedSecretGetter
func NewTemplatedSecretGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.SecretGetter { return templatedSecretGetter{dependencies: dependencies, t: t, node: node} }
go
func NewTemplatedSecretGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.SecretGetter { return templatedSecretGetter{dependencies: dependencies, t: t, node: node} }
[ "func", "NewTemplatedSecretGetter", "(", "dependencies", "exec", ".", "DependencyGetter", ",", "t", "*", "api", ".", "Task", ",", "node", "*", "api", ".", "NodeDescription", ")", "exec", ".", "SecretGetter", "{", "return", "templatedSecretGetter", "{", "dependen...
// NewTemplatedSecretGetter returns a SecretGetter that evaluates templates.
[ "NewTemplatedSecretGetter", "returns", "a", "SecretGetter", "that", "evaluates", "templates", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/template/getter.go#L16-L18
train
docker/swarmkit
template/getter.go
NewTemplatedConfigGetter
func NewTemplatedConfigGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) TemplatedConfigGetter { return templatedConfigGetter{dependencies: dependencies, t: t, node: node} }
go
func NewTemplatedConfigGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) TemplatedConfigGetter { return templatedConfigGetter{dependencies: dependencies, t: t, node: node} }
[ "func", "NewTemplatedConfigGetter", "(", "dependencies", "exec", ".", "DependencyGetter", ",", "t", "*", "api", ".", "Task", ",", "node", "*", "api", ".", "NodeDescription", ")", "TemplatedConfigGetter", "{", "return", "templatedConfigGetter", "{", "dependencies", ...
// NewTemplatedConfigGetter returns a ConfigGetter that evaluates templates.
[ "NewTemplatedConfigGetter", "returns", "a", "ConfigGetter", "that", "evaluates", "templates", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/template/getter.go#L64-L66
train
docker/swarmkit
template/getter.go
NewTemplatedDependencyGetter
func NewTemplatedDependencyGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.DependencyGetter { return templatedDependencyGetter{ secrets: NewTemplatedSecretGetter(dependencies, t, node), configs: NewTemplatedConfigGetter(dependencies, t, node), } }
go
func NewTemplatedDependencyGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.DependencyGetter { return templatedDependencyGetter{ secrets: NewTemplatedSecretGetter(dependencies, t, node), configs: NewTemplatedConfigGetter(dependencies, t, node), } }
[ "func", "NewTemplatedDependencyGetter", "(", "dependencies", "exec", ".", "DependencyGetter", ",", "t", "*", "api", ".", "Task", ",", "node", "*", "api", ".", "NodeDescription", ")", "exec", ".", "DependencyGetter", "{", "return", "templatedDependencyGetter", "{",...
// NewTemplatedDependencyGetter returns a DependencyGetter that evaluates templates.
[ "NewTemplatedDependencyGetter", "returns", "a", "DependencyGetter", "that", "evaluates", "templates", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/template/getter.go#L104-L109
train
docker/swarmkit
manager/state/raft/storage/storage.go
BootstrapNew
func (e *EncryptedRaftLogger) BootstrapNew(metadata []byte) error { e.encoderMu.Lock() defer e.encoderMu.Unlock() encrypter, decrypter := encryption.Defaults(e.EncryptionKey, e.FIPS) walFactory := NewWALFactory(encrypter, decrypter) for _, dirpath := range []string{filepath.Dir(e.walDir()), e.snapDir()} { if er...
go
func (e *EncryptedRaftLogger) BootstrapNew(metadata []byte) error { e.encoderMu.Lock() defer e.encoderMu.Unlock() encrypter, decrypter := encryption.Defaults(e.EncryptionKey, e.FIPS) walFactory := NewWALFactory(encrypter, decrypter) for _, dirpath := range []string{filepath.Dir(e.walDir()), e.snapDir()} { if er...
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "BootstrapNew", "(", "metadata", "[", "]", "byte", ")", "error", "{", "e", ".", "encoderMu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "encoderMu", ".", "Unlock", "(", ")", "\n", "encrypter", "...
// BootstrapNew creates a new snapshotter and WAL writer, expecting that there is nothing on disk
[ "BootstrapNew", "creates", "a", "new", "snapshotter", "and", "WAL", "writer", "expecting", "that", "there", "is", "nothing", "on", "disk" ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L143-L163
train
docker/swarmkit
manager/state/raft/storage/storage.go
RotateEncryptionKey
func (e *EncryptedRaftLogger) RotateEncryptionKey(newKey []byte) { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { // if the wal exists, the snapshotter exists // We don't want to have to close the WAL, because we can't open a new one. // We need to know the previous snapshot, because when you o...
go
func (e *EncryptedRaftLogger) RotateEncryptionKey(newKey []byte) { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { // if the wal exists, the snapshotter exists // We don't want to have to close the WAL, because we can't open a new one. // We need to know the previous snapshot, because when you o...
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "RotateEncryptionKey", "(", "newKey", "[", "]", "byte", ")", "{", "e", ".", "encoderMu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "encoderMu", ".", "Unlock", "(", ")", "\n\n", "if", "e", ".", ...
// RotateEncryptionKey swaps out the encoders and decoders used by the wal and snapshotter
[ "RotateEncryptionKey", "swaps", "out", "the", "encoders", "and", "decoders", "used", "by", "the", "wal", "and", "snapshotter" ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L174-L194
train
docker/swarmkit
manager/state/raft/storage/storage.go
SaveSnapshot
func (e *EncryptedRaftLogger) SaveSnapshot(snapshot raftpb.Snapshot) error { walsnap := walpb.Snapshot{ Index: snapshot.Metadata.Index, Term: snapshot.Metadata.Term, } e.encoderMu.RLock() if err := e.wal.SaveSnapshot(walsnap); err != nil { e.encoderMu.RUnlock() return err } snapshotter := e.snapshotte...
go
func (e *EncryptedRaftLogger) SaveSnapshot(snapshot raftpb.Snapshot) error { walsnap := walpb.Snapshot{ Index: snapshot.Metadata.Index, Term: snapshot.Metadata.Term, } e.encoderMu.RLock() if err := e.wal.SaveSnapshot(walsnap); err != nil { e.encoderMu.RUnlock() return err } snapshotter := e.snapshotte...
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "SaveSnapshot", "(", "snapshot", "raftpb", ".", "Snapshot", ")", "error", "{", "walsnap", ":=", "walpb", ".", "Snapshot", "{", "Index", ":", "snapshot", ".", "Metadata", ".", "Index", ",", "Term", ":", "...
// SaveSnapshot actually saves a given snapshot to both the WAL and the snapshot.
[ "SaveSnapshot", "actually", "saves", "a", "given", "snapshot", "to", "both", "the", "WAL", "and", "the", "snapshot", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L197-L217
train
docker/swarmkit
manager/state/raft/storage/storage.go
GC
func (e *EncryptedRaftLogger) GC(index uint64, term uint64, keepOldSnapshots uint64) error { // Delete any older snapshots curSnapshot := fmt.Sprintf("%016x-%016x%s", term, index, ".snap") snapshots, err := ListSnapshots(e.snapDir()) if err != nil { return err } // Ignore any snapshots that are older than the...
go
func (e *EncryptedRaftLogger) GC(index uint64, term uint64, keepOldSnapshots uint64) error { // Delete any older snapshots curSnapshot := fmt.Sprintf("%016x-%016x%s", term, index, ".snap") snapshots, err := ListSnapshots(e.snapDir()) if err != nil { return err } // Ignore any snapshots that are older than the...
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "GC", "(", "index", "uint64", ",", "term", "uint64", ",", "keepOldSnapshots", "uint64", ")", "error", "{", "// Delete any older snapshots", "curSnapshot", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "...
// GC garbage collects snapshots and wals older than the provided index and term
[ "GC", "garbage", "collects", "snapshots", "and", "wals", "older", "than", "the", "provided", "index", "and", "term" ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L220-L316
train
docker/swarmkit
manager/state/raft/storage/storage.go
SaveEntries
func (e *EncryptedRaftLogger) SaveEntries(st raftpb.HardState, entries []raftpb.Entry) error { e.encoderMu.RLock() defer e.encoderMu.RUnlock() if e.wal == nil { return fmt.Errorf("raft WAL has either been closed or has never been created") } return e.wal.Save(st, entries) }
go
func (e *EncryptedRaftLogger) SaveEntries(st raftpb.HardState, entries []raftpb.Entry) error { e.encoderMu.RLock() defer e.encoderMu.RUnlock() if e.wal == nil { return fmt.Errorf("raft WAL has either been closed or has never been created") } return e.wal.Save(st, entries) }
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "SaveEntries", "(", "st", "raftpb", ".", "HardState", ",", "entries", "[", "]", "raftpb", ".", "Entry", ")", "error", "{", "e", ".", "encoderMu", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "enc...
// SaveEntries saves only entries to disk
[ "SaveEntries", "saves", "only", "entries", "to", "disk" ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L319-L327
train
docker/swarmkit
manager/state/raft/storage/storage.go
Close
func (e *EncryptedRaftLogger) Close(ctx context.Context) { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { if err := e.wal.Close(); err != nil { log.G(ctx).WithError(err).Error("error closing raft WAL") } } e.wal = nil e.snapshotter = nil }
go
func (e *EncryptedRaftLogger) Close(ctx context.Context) { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { if err := e.wal.Close(); err != nil { log.G(ctx).WithError(err).Error("error closing raft WAL") } } e.wal = nil e.snapshotter = nil }
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "Close", "(", "ctx", "context", ".", "Context", ")", "{", "e", ".", "encoderMu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "encoderMu", ".", "Unlock", "(", ")", "\n\n", "if", "e", ".", "wal",...
// Close closes the logger - it will have to be bootstrapped again to start writing
[ "Close", "closes", "the", "logger", "-", "it", "will", "have", "to", "be", "bootstrapped", "again", "to", "start", "writing" ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L330-L342
train
docker/swarmkit
manager/state/raft/storage/storage.go
Clear
func (e *EncryptedRaftLogger) Clear(ctx context.Context) error { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { if err := e.wal.Close(); err != nil { log.G(ctx).WithError(err).Error("error closing raft WAL") } } e.snapshotter = nil os.RemoveAll(e.walDir()) os.RemoveAll(e.snapDir()) ret...
go
func (e *EncryptedRaftLogger) Clear(ctx context.Context) error { e.encoderMu.Lock() defer e.encoderMu.Unlock() if e.wal != nil { if err := e.wal.Close(); err != nil { log.G(ctx).WithError(err).Error("error closing raft WAL") } } e.snapshotter = nil os.RemoveAll(e.walDir()) os.RemoveAll(e.snapDir()) ret...
[ "func", "(", "e", "*", "EncryptedRaftLogger", ")", "Clear", "(", "ctx", "context", ".", "Context", ")", "error", "{", "e", ".", "encoderMu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "encoderMu", ".", "Unlock", "(", ")", "\n\n", "if", "e", "....
// Clear closes the existing WAL and removes the WAL and snapshot.
[ "Clear", "closes", "the", "existing", "WAL", "and", "removes", "the", "WAL", "and", "snapshot", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/storage.go#L345-L359
train
docker/swarmkit
agent/worker.go
Init
func (w *worker) Init(ctx context.Context) error { w.mu.Lock() defer w.mu.Unlock() ctx = log.WithModule(ctx, "worker") // TODO(stevvooe): Start task cleanup process. // read the tasks from the database and start any task managers that may be needed. return w.db.Update(func(tx *bolt.Tx) error { return WalkTas...
go
func (w *worker) Init(ctx context.Context) error { w.mu.Lock() defer w.mu.Unlock() ctx = log.WithModule(ctx, "worker") // TODO(stevvooe): Start task cleanup process. // read the tasks from the database and start any task managers that may be needed. return w.db.Update(func(tx *bolt.Tx) error { return WalkTas...
[ "func", "(", "w", "*", "worker", ")", "Init", "(", "ctx", "context", ".", "Context", ")", "error", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "ctx", "=", "log", ".", "WithModule",...
// Init prepares the worker for assignments.
[ "Init", "prepares", "the", "worker", "for", "assignments", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/worker.go#L84-L115
train
docker/swarmkit
agent/worker.go
Close
func (w *worker) Close() { w.mu.Lock() w.closed = true w.mu.Unlock() w.taskevents.Close() }
go
func (w *worker) Close() { w.mu.Lock() w.closed = true w.mu.Unlock() w.taskevents.Close() }
[ "func", "(", "w", "*", "worker", ")", "Close", "(", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "w", ".", "closed", "=", "true", "\n", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "w", ".", "taskevents", ".", "Close", "(", ")...
// Close performs worker cleanup when no longer needed.
[ "Close", "performs", "worker", "cleanup", "when", "no", "longer", "needed", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/worker.go#L118-L124
train
docker/swarmkit
agent/worker.go
Assign
func (w *worker) Assign(ctx context.Context, assignments []*api.AssignmentChange) error { w.mu.Lock() defer w.mu.Unlock() if w.closed { return ErrClosed } log.G(ctx).WithFields(logrus.Fields{ "len(assignments)": len(assignments), }).Debug("(*worker).Assign") // Need to update dependencies before tasks e...
go
func (w *worker) Assign(ctx context.Context, assignments []*api.AssignmentChange) error { w.mu.Lock() defer w.mu.Unlock() if w.closed { return ErrClosed } log.G(ctx).WithFields(logrus.Fields{ "len(assignments)": len(assignments), }).Debug("(*worker).Assign") // Need to update dependencies before tasks e...
[ "func", "(", "w", "*", "worker", ")", "Assign", "(", "ctx", "context", ".", "Context", ",", "assignments", "[", "]", "*", "api", ".", "AssignmentChange", ")", "error", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", "."...
// Assign assigns a full set of tasks, configs, and secrets to the worker. // Any tasks not previously known will be started. Any tasks that are in the task set // and already running will be updated, if possible. Any tasks currently running on // the worker outside the task set will be terminated. // Anything not in t...
[ "Assign", "assigns", "a", "full", "set", "of", "tasks", "configs", "and", "secrets", "to", "the", "worker", ".", "Any", "tasks", "not", "previously", "known", "will", "be", "started", ".", "Any", "tasks", "that", "are", "in", "the", "task", "set", "and",...
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/worker.go#L131-L156
train
docker/swarmkit
agent/worker.go
updateTaskStatus
func (w *worker) updateTaskStatus(ctx context.Context, tx *bolt.Tx, taskID string, status *api.TaskStatus) error { if err := PutTaskStatus(tx, taskID, status); err != nil { log.G(ctx).WithError(err).Error("failed writing status to disk") return err } // broadcast the task status out. for key := range w.listene...
go
func (w *worker) updateTaskStatus(ctx context.Context, tx *bolt.Tx, taskID string, status *api.TaskStatus) error { if err := PutTaskStatus(tx, taskID, status); err != nil { log.G(ctx).WithError(err).Error("failed writing status to disk") return err } // broadcast the task status out. for key := range w.listene...
[ "func", "(", "w", "*", "worker", ")", "updateTaskStatus", "(", "ctx", "context", ".", "Context", ",", "tx", "*", "bolt", ".", "Tx", ",", "taskID", "string", ",", "status", "*", "api", ".", "TaskStatus", ")", "error", "{", "if", "err", ":=", "PutTaskS...
// updateTaskStatus reports statuses to listeners, read lock must be held.
[ "updateTaskStatus", "reports", "statuses", "to", "listeners", "read", "lock", "must", "be", "held", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/worker.go#L501-L515
train
docker/swarmkit
agent/worker.go
Subscribe
func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMessage) error { log.G(ctx).Debugf("Received subscription %s (selector: %v)", subscription.ID, subscription.Selector) publisher, cancel, err := w.publisherProvider.Publisher(ctx, subscription.ID) if err != nil { return err } // Send a...
go
func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMessage) error { log.G(ctx).Debugf("Received subscription %s (selector: %v)", subscription.ID, subscription.Selector) publisher, cancel, err := w.publisherProvider.Publisher(ctx, subscription.ID) if err != nil { return err } // Send a...
[ "func", "(", "w", "*", "worker", ")", "Subscribe", "(", "ctx", "context", ".", "Context", ",", "subscription", "*", "api", ".", "SubscriptionMessage", ")", "error", "{", "log", ".", "G", "(", "ctx", ")", ".", "Debugf", "(", "\"", "\"", ",", "subscrip...
// Subscribe to log messages matching the subscription.
[ "Subscribe", "to", "log", "messages", "matching", "the", "subscription", "." ]
59163bf75df38489d4a10392265d27156dc473c5
https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/worker.go#L518-L603
train
spf13/afero
ioutil.go
ReadDir
func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) { return ReadDir(a.Fs, dirname) }
go
func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) { return ReadDir(a.Fs, dirname) }
[ "func", "(", "a", "Afero", ")", "ReadDir", "(", "dirname", "string", ")", "(", "[", "]", "os", ".", "FileInfo", ",", "error", ")", "{", "return", "ReadDir", "(", "a", ".", "Fs", ",", "dirname", ")", "\n", "}" ]
// ReadDir reads the directory named by dirname and returns // a list of sorted directory entries.
[ "ReadDir", "reads", "the", "directory", "named", "by", "dirname", "and", "returns", "a", "list", "of", "sorted", "directory", "entries", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/ioutil.go#L38-L40
train
spf13/afero
ioutil.go
ReadFile
func (a Afero) ReadFile(filename string) ([]byte, error) { return ReadFile(a.Fs, filename) }
go
func (a Afero) ReadFile(filename string) ([]byte, error) { return ReadFile(a.Fs, filename) }
[ "func", "(", "a", "Afero", ")", "ReadFile", "(", "filename", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "ReadFile", "(", "a", ".", "Fs", ",", "filename", ")", "\n", "}" ]
// ReadFile reads the file named by filename and returns the contents. // A successful call returns err == nil, not err == EOF. Because ReadFile // reads the whole file, it does not treat an EOF from Read as an error // to be reported.
[ "ReadFile", "reads", "the", "file", "named", "by", "filename", "and", "returns", "the", "contents", ".", "A", "successful", "call", "returns", "err", "==", "nil", "not", "err", "==", "EOF", ".", "Because", "ReadFile", "reads", "the", "whole", "file", "it",...
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/ioutil.go#L60-L62
train
spf13/afero
ioutil.go
readAll
func readAll(r io.Reader, capacity int64) (b []byte, err error) { buf := bytes.NewBuffer(make([]byte, 0, capacity)) // If the buffer overflows, we will get bytes.ErrTooLarge. // Return that as an error. Any other panic remains. defer func() { e := recover() if e == nil { return } if panicErr, ok := e.(er...
go
func readAll(r io.Reader, capacity int64) (b []byte, err error) { buf := bytes.NewBuffer(make([]byte, 0, capacity)) // If the buffer overflows, we will get bytes.ErrTooLarge. // Return that as an error. Any other panic remains. defer func() { e := recover() if e == nil { return } if panicErr, ok := e.(er...
[ "func", "readAll", "(", "r", "io", ".", "Reader", ",", "capacity", "int64", ")", "(", "b", "[", "]", "byte", ",", "err", "error", ")", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "make", "(", "[", "]", "byte", ",", "0", ",", "capacity", "...
// readAll reads from r until an error or EOF and returns the data it read // from the internal buffer allocated with a specified capacity.
[ "readAll", "reads", "from", "r", "until", "an", "error", "or", "EOF", "and", "returns", "the", "data", "it", "read", "from", "the", "internal", "buffer", "allocated", "with", "a", "specified", "capacity", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/ioutil.go#L90-L107
train
spf13/afero
ioutil.go
WriteFile
func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error { return WriteFile(a.Fs, filename, data, perm) }
go
func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error { return WriteFile(a.Fs, filename, data, perm) }
[ "func", "(", "a", "Afero", ")", "WriteFile", "(", "filename", "string", ",", "data", "[", "]", "byte", ",", "perm", "os", ".", "FileMode", ")", "error", "{", "return", "WriteFile", "(", "a", ".", "Fs", ",", "filename", ",", "data", ",", "perm", ")"...
// WriteFile writes data to a file named by filename. // If the file does not exist, WriteFile creates it with permissions perm; // otherwise WriteFile truncates it before writing.
[ "WriteFile", "writes", "data", "to", "a", "file", "named", "by", "filename", ".", "If", "the", "file", "does", "not", "exist", "WriteFile", "creates", "it", "with", "permissions", "perm", ";", "otherwise", "WriteFile", "truncates", "it", "before", "writing", ...
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/ioutil.go#L120-L122
train
spf13/afero
util.go
WriteReader
func (a Afero) WriteReader(path string, r io.Reader) (err error) { return WriteReader(a.Fs, path, r) }
go
func (a Afero) WriteReader(path string, r io.Reader) (err error) { return WriteReader(a.Fs, path, r) }
[ "func", "(", "a", "Afero", ")", "WriteReader", "(", "path", "string", ",", "r", "io", ".", "Reader", ")", "(", "err", "error", ")", "{", "return", "WriteReader", "(", "a", ".", "Fs", ",", "path", ",", "r", ")", "\n", "}" ]
// Takes a reader and a path and writes the content
[ "Takes", "a", "reader", "and", "a", "path", "and", "writes", "the", "content" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L36-L38
train
spf13/afero
util.go
GetTempDir
func GetTempDir(fs Fs, subPath string) string { addSlash := func(p string) string { if FilePathSeparator != p[len(p)-1:] { p = p + FilePathSeparator } return p } dir := addSlash(os.TempDir()) if subPath != "" { // preserve windows backslash :-( if FilePathSeparator == "\\" { subPath = strings.Repla...
go
func GetTempDir(fs Fs, subPath string) string { addSlash := func(p string) string { if FilePathSeparator != p[len(p)-1:] { p = p + FilePathSeparator } return p } dir := addSlash(os.TempDir()) if subPath != "" { // preserve windows backslash :-( if FilePathSeparator == "\\" { subPath = strings.Repla...
[ "func", "GetTempDir", "(", "fs", "Fs", ",", "subPath", "string", ")", "string", "{", "addSlash", ":=", "func", "(", "p", "string", ")", "string", "{", "if", "FilePathSeparator", "!=", "p", "[", "len", "(", "p", ")", "-", "1", ":", "]", "{", "p", ...
// GetTempDir returns the default temp directory with trailing slash // if subPath is not empty then it will be created recursively with mode 777 rwx rwx rwx
[ "GetTempDir", "returns", "the", "default", "temp", "directory", "with", "trailing", "slash", "if", "subPath", "is", "not", "empty", "then", "it", "will", "be", "created", "recursively", "with", "mode", "777", "rwx", "rwx", "rwx" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L103-L133
train
spf13/afero
util.go
UnicodeSanitize
func UnicodeSanitize(s string) string { source := []rune(s) target := make([]rune, 0, len(source)) for _, r := range source { if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsMark(r) || r == '.' || r == '/' || r == '\\' || r == '_' || r == '-' || r == '%' || r == ' ' || r ==...
go
func UnicodeSanitize(s string) string { source := []rune(s) target := make([]rune, 0, len(source)) for _, r := range source { if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsMark(r) || r == '.' || r == '/' || r == '\\' || r == '_' || r == '-' || r == '%' || r == ' ' || r ==...
[ "func", "UnicodeSanitize", "(", "s", "string", ")", "string", "{", "source", ":=", "[", "]", "rune", "(", "s", ")", "\n", "target", ":=", "make", "(", "[", "]", "rune", ",", "0", ",", "len", "(", "source", ")", ")", "\n\n", "for", "_", ",", "r"...
// Rewrite string to remove non-standard path characters
[ "Rewrite", "string", "to", "remove", "non", "-", "standard", "path", "characters" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L136-L157
train
spf13/afero
util.go
NeuterAccents
func NeuterAccents(s string) string { t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC) result, _, _ := transform.String(t, string(s)) return result }
go
func NeuterAccents(s string) string { t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC) result, _, _ := transform.String(t, string(s)) return result }
[ "func", "NeuterAccents", "(", "s", "string", ")", "string", "{", "t", ":=", "transform", ".", "Chain", "(", "norm", ".", "NFD", ",", "transform", ".", "RemoveFunc", "(", "isMn", ")", ",", "norm", ".", "NFC", ")", "\n", "result", ",", "_", ",", "_",...
// Transform characters with accents into plain forms.
[ "Transform", "characters", "with", "accents", "into", "plain", "forms", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L160-L165
train
spf13/afero
util.go
FileContainsBytes
func FileContainsBytes(fs Fs, filename string, subslice []byte) (bool, error) { f, err := fs.Open(filename) if err != nil { return false, err } defer f.Close() return readerContainsAny(f, subslice), nil }
go
func FileContainsBytes(fs Fs, filename string, subslice []byte) (bool, error) { f, err := fs.Open(filename) if err != nil { return false, err } defer f.Close() return readerContainsAny(f, subslice), nil }
[ "func", "FileContainsBytes", "(", "fs", "Fs", ",", "filename", "string", ",", "subslice", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "f", ",", "err", ":=", "fs", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", ...
// Check if a file contains a specified byte slice.
[ "Check", "if", "a", "file", "contains", "a", "specified", "byte", "slice", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L176-L184
train
spf13/afero
util.go
FileContainsAnyBytes
func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, error) { f, err := fs.Open(filename) if err != nil { return false, err } defer f.Close() return readerContainsAny(f, subslices...), nil }
go
func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, error) { f, err := fs.Open(filename) if err != nil { return false, err } defer f.Close() return readerContainsAny(f, subslices...), nil }
[ "func", "FileContainsAnyBytes", "(", "fs", "Fs", ",", "filename", "string", ",", "subslices", "[", "]", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "f", ",", "err", ":=", "fs", ".", "Open", "(", "filename", ")", "\n", "if", "err", ...
// Check if a file contains any of the specified byte slices.
[ "Check", "if", "a", "file", "contains", "any", "of", "the", "specified", "byte", "slices", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L191-L199
train
spf13/afero
util.go
readerContainsAny
func readerContainsAny(r io.Reader, subslices ...[]byte) bool { if r == nil || len(subslices) == 0 { return false } largestSlice := 0 for _, sl := range subslices { if len(sl) > largestSlice { largestSlice = len(sl) } } if largestSlice == 0 { return false } bufflen := largestSlice * 4 halflen :...
go
func readerContainsAny(r io.Reader, subslices ...[]byte) bool { if r == nil || len(subslices) == 0 { return false } largestSlice := 0 for _, sl := range subslices { if len(sl) > largestSlice { largestSlice = len(sl) } } if largestSlice == 0 { return false } bufflen := largestSlice * 4 halflen :...
[ "func", "readerContainsAny", "(", "r", "io", ".", "Reader", ",", "subslices", "...", "[", "]", "byte", ")", "bool", "{", "if", "r", "==", "nil", "||", "len", "(", "subslices", ")", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "largestSlice",...
// readerContains reports whether any of the subslices is within r.
[ "readerContains", "reports", "whether", "any", "of", "the", "subslices", "is", "within", "r", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L202-L251
train
spf13/afero
util.go
IsEmpty
func IsEmpty(fs Fs, path string) (bool, error) { if b, _ := Exists(fs, path); !b { return false, fmt.Errorf("%q path does not exist", path) } fi, err := fs.Stat(path) if err != nil { return false, err } if fi.IsDir() { f, err := fs.Open(path) if err != nil { return false, err } defer f.Close() li...
go
func IsEmpty(fs Fs, path string) (bool, error) { if b, _ := Exists(fs, path); !b { return false, fmt.Errorf("%q path does not exist", path) } fi, err := fs.Stat(path) if err != nil { return false, err } if fi.IsDir() { f, err := fs.Open(path) if err != nil { return false, err } defer f.Close() li...
[ "func", "IsEmpty", "(", "fs", "Fs", ",", "path", "string", ")", "(", "bool", ",", "error", ")", "{", "if", "b", ",", "_", ":=", "Exists", "(", "fs", ",", "path", ")", ";", "!", "b", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\""...
// IsEmpty checks if a given file or directory is empty.
[ "IsEmpty", "checks", "if", "a", "given", "file", "or", "directory", "is", "empty", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/util.go#L287-L305
train
spf13/afero
mem/file.go
Name
func (s *FileInfo) Name() string { s.Lock() _, name := filepath.Split(s.name) s.Unlock() return name }
go
func (s *FileInfo) Name() string { s.Lock() _, name := filepath.Split(s.name) s.Unlock() return name }
[ "func", "(", "s", "*", "FileInfo", ")", "Name", "(", ")", "string", "{", "s", ".", "Lock", "(", ")", "\n", "_", ",", "name", ":=", "filepath", ".", "Split", "(", "s", ".", "name", ")", "\n", "s", ".", "Unlock", "(", ")", "\n", "return", "name...
// Implements os.FileInfo
[ "Implements", "os", ".", "FileInfo" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/mem/file.go#L279-L284
train
spf13/afero
memmap.go
normalizePath
func normalizePath(path string) string { path = filepath.Clean(path) switch path { case ".": return FilePathSeparator case "..": return FilePathSeparator default: return path } }
go
func normalizePath(path string) string { path = filepath.Clean(path) switch path { case ".": return FilePathSeparator case "..": return FilePathSeparator default: return path } }
[ "func", "normalizePath", "(", "path", "string", ")", "string", "{", "path", "=", "filepath", ".", "Clean", "(", "path", ")", "\n\n", "switch", "path", "{", "case", "\"", "\"", ":", "return", "FilePathSeparator", "\n", "case", "\"", "\"", ":", "return", ...
// Handle some relative paths
[ "Handle", "some", "relative", "paths" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/memmap.go#L161-L172
train
spf13/afero
basepath.go
RealPath
func (b *BasePathFs) RealPath(name string) (path string, err error) { if err := validateBasePathName(name); err != nil { return name, err } bpath := filepath.Clean(b.path) path = filepath.Clean(filepath.Join(bpath, name)) if !strings.HasPrefix(path, bpath) { return name, os.ErrNotExist } return path, nil }
go
func (b *BasePathFs) RealPath(name string) (path string, err error) { if err := validateBasePathName(name); err != nil { return name, err } bpath := filepath.Clean(b.path) path = filepath.Clean(filepath.Join(bpath, name)) if !strings.HasPrefix(path, bpath) { return name, os.ErrNotExist } return path, nil }
[ "func", "(", "b", "*", "BasePathFs", ")", "RealPath", "(", "name", "string", ")", "(", "path", "string", ",", "err", "error", ")", "{", "if", "err", ":=", "validateBasePathName", "(", "name", ")", ";", "err", "!=", "nil", "{", "return", "name", ",", ...
// on a file outside the base path it returns the given file name and an error, // else the given file with the base path prepended
[ "on", "a", "file", "outside", "the", "base", "path", "it", "returns", "the", "given", "file", "name", "and", "an", "error", "else", "the", "given", "file", "with", "the", "base", "path", "prepended" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/basepath.go#L42-L54
train
spf13/afero
unionFile.go
Readdir
func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) { var merge DirsMerger = f.Merger if merge == nil { merge = defaultUnionMergeDirsFn } if f.off == 0 { var lfi []os.FileInfo if f.Layer != nil { lfi, err = f.Layer.Readdir(-1) if err != nil { return nil, err } } var bfi []os.F...
go
func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) { var merge DirsMerger = f.Merger if merge == nil { merge = defaultUnionMergeDirsFn } if f.off == 0 { var lfi []os.FileInfo if f.Layer != nil { lfi, err = f.Layer.Readdir(-1) if err != nil { return nil, err } } var bfi []os.F...
[ "func", "(", "f", "*", "UnionFile", ")", "Readdir", "(", "c", "int", ")", "(", "ofi", "[", "]", "os", ".", "FileInfo", ",", "err", "error", ")", "{", "var", "merge", "DirsMerger", "=", "f", ".", "Merger", "\n", "if", "merge", "==", "nil", "{", ...
// Readdir will weave the two directories together and // return a single view of the overlayed directories. // At the end of the directory view, the error is io.EOF if c > 0.
[ "Readdir", "will", "weave", "the", "two", "directories", "together", "and", "return", "a", "single", "view", "of", "the", "overlayed", "directories", ".", "At", "the", "end", "of", "the", "directory", "view", "the", "error", "is", "io", ".", "EOF", "if", ...
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/unionFile.go#L160-L208
train
spf13/afero
copyOnWriteFs.go
isBaseFile
func (u *CopyOnWriteFs) isBaseFile(name string) (bool, error) { if _, err := u.layer.Stat(name); err == nil { return false, nil } _, err := u.base.Stat(name) if err != nil { if oerr, ok := err.(*os.PathError); ok { if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || oerr.Err == syscall.ENOTDIR { ...
go
func (u *CopyOnWriteFs) isBaseFile(name string) (bool, error) { if _, err := u.layer.Stat(name); err == nil { return false, nil } _, err := u.base.Stat(name) if err != nil { if oerr, ok := err.(*os.PathError); ok { if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || oerr.Err == syscall.ENOTDIR { ...
[ "func", "(", "u", "*", "CopyOnWriteFs", ")", "isBaseFile", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "u", ".", "layer", ".", "Stat", "(", "name", ")", ";", "err", "==", "nil", "{", "return", "...
// Returns true if the file is not in the overlay
[ "Returns", "true", "if", "the", "file", "is", "not", "in", "the", "overlay" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/copyOnWriteFs.go#L30-L46
train
spf13/afero
copyOnWriteFs.go
Rename
func (u *CopyOnWriteFs) Rename(oldname, newname string) error { b, err := u.isBaseFile(oldname) if err != nil { return err } if b { return syscall.EPERM } return u.layer.Rename(oldname, newname) }
go
func (u *CopyOnWriteFs) Rename(oldname, newname string) error { b, err := u.isBaseFile(oldname) if err != nil { return err } if b { return syscall.EPERM } return u.layer.Rename(oldname, newname) }
[ "func", "(", "u", "*", "CopyOnWriteFs", ")", "Rename", "(", "oldname", ",", "newname", "string", ")", "error", "{", "b", ",", "err", ":=", "u", ".", "isBaseFile", "(", "oldname", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}",...
// Renaming files present only in the base layer is not permitted
[ "Renaming", "files", "present", "only", "in", "the", "base", "layer", "is", "not", "permitted" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/copyOnWriteFs.go#L131-L140
train
spf13/afero
copyOnWriteFs.go
Remove
func (u *CopyOnWriteFs) Remove(name string) error { err := u.layer.Remove(name) switch err { case syscall.ENOENT: _, err = u.base.Stat(name) if err == nil { return syscall.EPERM } return syscall.ENOENT default: return err } }
go
func (u *CopyOnWriteFs) Remove(name string) error { err := u.layer.Remove(name) switch err { case syscall.ENOENT: _, err = u.base.Stat(name) if err == nil { return syscall.EPERM } return syscall.ENOENT default: return err } }
[ "func", "(", "u", "*", "CopyOnWriteFs", ")", "Remove", "(", "name", "string", ")", "error", "{", "err", ":=", "u", ".", "layer", ".", "Remove", "(", "name", ")", "\n", "switch", "err", "{", "case", "syscall", ".", "ENOENT", ":", "_", ",", "err", ...
// Removing files present only in the base layer is not permitted. If // a file is present in the base layer and the overlay, only the overlay // will be removed.
[ "Removing", "files", "present", "only", "in", "the", "base", "layer", "is", "not", "permitted", ".", "If", "a", "file", "is", "present", "in", "the", "base", "layer", "and", "the", "overlay", "only", "the", "overlay", "will", "be", "removed", "." ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/copyOnWriteFs.go#L145-L157
train
spf13/afero
path.go
lstatIfPossible
func lstatIfPossible(fs Fs, path string) (os.FileInfo, error) { if lfs, ok := fs.(Lstater); ok { fi, _, err := lfs.LstatIfPossible(path) return fi, err } return fs.Stat(path) }
go
func lstatIfPossible(fs Fs, path string) (os.FileInfo, error) { if lfs, ok := fs.(Lstater); ok { fi, _, err := lfs.LstatIfPossible(path) return fi, err } return fs.Stat(path) }
[ "func", "lstatIfPossible", "(", "fs", "Fs", ",", "path", "string", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "if", "lfs", ",", "ok", ":=", "fs", ".", "(", "Lstater", ")", ";", "ok", "{", "fi", ",", "_", ",", "err", ":=", "lfs", ...
// if the filesystem supports it, use Lstat, else use fs.Stat
[ "if", "the", "filesystem", "supports", "it", "use", "Lstat", "else", "use", "fs", ".", "Stat" ]
588a75ec4f32903aa5e39a2619ba6a4631e28424
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/path.go#L81-L87
train
requilence/integram
types.go
toBson
func (o *OAuthProvider) toBson() bson.M { return bson.M{"baseurl": struct { Scheme string Host string Path string }{o.BaseURL.Scheme, o.BaseURL.Host, o.BaseURL.Path}, "id": o.ID, "secret": o.Secret, "service": o.Service} }
go
func (o *OAuthProvider) toBson() bson.M { return bson.M{"baseurl": struct { Scheme string Host string Path string }{o.BaseURL.Scheme, o.BaseURL.Host, o.BaseURL.Path}, "id": o.ID, "secret": o.Secret, "service": o.Service} }
[ "func", "(", "o", "*", "OAuthProvider", ")", "toBson", "(", ")", "bson", ".", "M", "{", "return", "bson", ".", "M", "{", "\"", "\"", ":", "struct", "{", "Scheme", "string", "\n", "Host", "string", "\n", "Path", "string", "\n", "}", "{", "o", ".",...
// workaround to save urls as struct
[ "workaround", "to", "save", "urls", "as", "struct" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/types.go#L50-L60
train
requilence/integram
helpers.go
URLMustParse
func URLMustParse(s string) *url.URL { u, err := url.Parse(s) if err != nil { log.Errorf("Expected URL to parse: %q, got error: %v", s, err) } return u }
go
func URLMustParse(s string) *url.URL { u, err := url.Parse(s) if err != nil { log.Errorf("Expected URL to parse: %q, got error: %v", s, err) } return u }
[ "func", "URLMustParse", "(", "s", "string", ")", "*", "url", ".", "URL", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "s", ",", "err", ")", ...
// URLMustParse returns url.URL from static string. Don't use it with a dynamic param
[ "URLMustParse", "returns", "url", ".", "URL", "from", "static", "string", ".", "Don", "t", "use", "it", "with", "a", "dynamic", "param" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/helpers.go#L165-L171
train
requilence/integram
helpers.go
GetVersion
func GetVersion() string { if currentGitHead == "" { b, err := ioutil.ReadFile(".git/HEAD") if err != nil { currentGitHead = "unknown" return currentGitHead } p := refRE.FindStringSubmatch(string(b)) if len(p) < 2 { currentGitHead = string(b) return currentGitHead } b, err = ioutil.ReadFi...
go
func GetVersion() string { if currentGitHead == "" { b, err := ioutil.ReadFile(".git/HEAD") if err != nil { currentGitHead = "unknown" return currentGitHead } p := refRE.FindStringSubmatch(string(b)) if len(p) < 2 { currentGitHead = string(b) return currentGitHead } b, err = ioutil.ReadFi...
[ "func", "GetVersion", "(", ")", "string", "{", "if", "currentGitHead", "==", "\"", "\"", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "\"", "\"", ")", "\n\n", "if", "err", "!=", "nil", "{", "currentGitHead", "=", "\"", "\"", "\n", "r...
// GetVersion returns the current HEAD git commit if .git exists
[ "GetVersion", "returns", "the", "current", "HEAD", "git", "commit", "if", ".", "git", "exists" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/helpers.go#L200-L225
train
requilence/integram
data.go
Cache
func (user *User) Cache(key string, res interface{}) (exists bool) { return user.ctx.getCacheVal("user", key, res) }
go
func (user *User) Cache(key string, res interface{}) (exists bool) { return user.ctx.getCacheVal("user", key, res) }
[ "func", "(", "user", "*", "User", ")", "Cache", "(", "key", "string", ",", "res", "interface", "{", "}", ")", "(", "exists", "bool", ")", "{", "return", "user", ".", "ctx", ".", "getCacheVal", "(", "\"", "\"", ",", "key", ",", "res", ")", "\n", ...
// Cache returns if User's cache for specific key exists and try to bind it to res
[ "Cache", "returns", "if", "User", "s", "cache", "for", "specific", "key", "exists", "and", "try", "to", "bind", "it", "to", "res" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L377-L379
train
requilence/integram
data.go
Cache
func (chat *Chat) Cache(key string, res interface{}) (exists bool) { return chat.ctx.getCacheVal("chat", key, res) }
go
func (chat *Chat) Cache(key string, res interface{}) (exists bool) { return chat.ctx.getCacheVal("chat", key, res) }
[ "func", "(", "chat", "*", "Chat", ")", "Cache", "(", "key", "string", ",", "res", "interface", "{", "}", ")", "(", "exists", "bool", ")", "{", "return", "chat", ".", "ctx", ".", "getCacheVal", "(", "\"", "\"", ",", "key", ",", "res", ")", "\n", ...
// Cache returns if Chat's cache for specific key exists and try to bind it to res
[ "Cache", "returns", "if", "Chat", "s", "cache", "for", "specific", "key", "exists", "and", "try", "to", "bind", "it", "to", "res" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L382-L384
train
requilence/integram
data.go
ServiceCache
func (c *Context) ServiceCache(key string, res interface{}) (exists bool) { return c.getCacheVal("service", key, res) }
go
func (c *Context) ServiceCache(key string, res interface{}) (exists bool) { return c.getCacheVal("service", key, res) }
[ "func", "(", "c", "*", "Context", ")", "ServiceCache", "(", "key", "string", ",", "res", "interface", "{", "}", ")", "(", "exists", "bool", ")", "{", "return", "c", ".", "getCacheVal", "(", "\"", "\"", ",", "key", ",", "res", ")", "\n", "}" ]
// ServiceCache returns if Services's cache for specific key exists and try to bind it to res
[ "ServiceCache", "returns", "if", "Services", "s", "cache", "for", "specific", "key", "exists", "and", "try", "to", "bind", "it", "to", "res" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L387-L389
train
requilence/integram
data.go
SetCache
func (user *User) SetCache(key string, val interface{}, ttl time.Duration) error { expiresAt := time.Now().Add(ttl) serviceID := user.ctx.getServiceID() key = strings.ToLower(key) if val == nil { err := user.ctx.db.C("users_cache").Remove(bson.M{"userid": user.ID, "service": serviceID, "key": key}) return err...
go
func (user *User) SetCache(key string, val interface{}, ttl time.Duration) error { expiresAt := time.Now().Add(ttl) serviceID := user.ctx.getServiceID() key = strings.ToLower(key) if val == nil { err := user.ctx.db.C("users_cache").Remove(bson.M{"userid": user.ID, "service": serviceID, "key": key}) return err...
[ "func", "(", "user", "*", "User", ")", "SetCache", "(", "key", "string", ",", "val", "interface", "{", "}", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "expiresAt", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "ttl", ")", "\n\...
// SetCache set the User's cache with specific key and TTL
[ "SetCache", "set", "the", "User", "s", "cache", "with", "specific", "key", "and", "TTL" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L405-L424
train
requilence/integram
data.go
UpdateCache
func (user *User) UpdateCache(key string, update interface{}, res interface{}) error { exists := user.ctx.updateCacheVal("user", key, update, res) if !exists { log.WithField("key", key).Error("Can't update user cache value") } return nil }
go
func (user *User) UpdateCache(key string, update interface{}, res interface{}) error { exists := user.ctx.updateCacheVal("user", key, update, res) if !exists { log.WithField("key", key).Error("Can't update user cache value") } return nil }
[ "func", "(", "user", "*", "User", ")", "UpdateCache", "(", "key", "string", ",", "update", "interface", "{", "}", ",", "res", "interface", "{", "}", ")", "error", "{", "exists", ":=", "user", ".", "ctx", ".", "updateCacheVal", "(", "\"", "\"", ",", ...
// UpdateCache updates the per User cache using MongoDB Update query
[ "UpdateCache", "updates", "the", "per", "User", "cache", "using", "MongoDB", "Update", "query" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L427-L435
train
requilence/integram
data.go
SetServiceCache
func (c *Context) SetServiceCache(key string, val interface{}, ttl time.Duration) error { expiresAt := time.Now().Add(ttl) serviceID := c.getServiceID() key = strings.ToLower(key) if val == nil { err := c.db.C("services_cache").Remove(bson.M{"service": serviceID, "key": key}) return err } _, err := c.db.C("...
go
func (c *Context) SetServiceCache(key string, val interface{}, ttl time.Duration) error { expiresAt := time.Now().Add(ttl) serviceID := c.getServiceID() key = strings.ToLower(key) if val == nil { err := c.db.C("services_cache").Remove(bson.M{"service": serviceID, "key": key}) return err } _, err := c.db.C("...
[ "func", "(", "c", "*", "Context", ")", "SetServiceCache", "(", "key", "string", ",", "val", "interface", "{", "}", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "expiresAt", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "ttl", ")",...
// SetServiceCache set the Services's cache with specific key and TTL
[ "SetServiceCache", "set", "the", "Services", "s", "cache", "with", "specific", "key", "and", "TTL" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L470-L489
train
requilence/integram
data.go
Settings
func (user *User) Settings(out interface{}) error { data, err := user.getData() if err != nil { return err } serviceID := user.ctx.getServiceID() if _, ok := data.Settings[serviceID]; ok { // TODO: workaround that creepy bindInterfaceToInterface err = bindInterfaceToInterface(data.Settings[serviceID], out)...
go
func (user *User) Settings(out interface{}) error { data, err := user.getData() if err != nil { return err } serviceID := user.ctx.getServiceID() if _, ok := data.Settings[serviceID]; ok { // TODO: workaround that creepy bindInterfaceToInterface err = bindInterfaceToInterface(data.Settings[serviceID], out)...
[ "func", "(", "user", "*", "User", ")", "Settings", "(", "out", "interface", "{", "}", ")", "error", "{", "data", ",", "err", ":=", "user", ".", "getData", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "service...
// Settings bind User's settings for service to the interface
[ "Settings", "bind", "User", "s", "settings", "for", "service", "to", "the", "interface" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L642-L658
train
requilence/integram
data.go
Settings
func (chat *Chat) Settings(out interface{}) error { data, err := chat.getData() if err != nil { return err } serviceID := chat.ctx.getServiceID() if _, ok := data.Settings[serviceID]; ok { // TODO: workaround that creepy bindInterfaceToInterface err = bindInterfaceToInterface(data.Settings[serviceID], out...
go
func (chat *Chat) Settings(out interface{}) error { data, err := chat.getData() if err != nil { return err } serviceID := chat.ctx.getServiceID() if _, ok := data.Settings[serviceID]; ok { // TODO: workaround that creepy bindInterfaceToInterface err = bindInterfaceToInterface(data.Settings[serviceID], out...
[ "func", "(", "chat", "*", "Chat", ")", "Settings", "(", "out", "interface", "{", "}", ")", "error", "{", "data", ",", "err", ":=", "chat", ".", "getData", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "service...
// Settings bind Chat's settings for service to the interface
[ "Settings", "bind", "Chat", "s", "settings", "for", "service", "to", "the", "interface" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L661-L678
train
requilence/integram
data.go
SaveSettings
func (chat *Chat) SaveSettings(allSettings interface{}) error { serviceID := chat.ctx.getServiceID() _, err := chat.ctx.db.C("chats").UpsertId(chat.ID, bson.M{"$set": bson.M{"settings." + serviceID: allSettings}, "$setOnInsert": bson.M{"createdat": time.Now()}}) if chat.data == nil { chat.data = &chatData{} } ...
go
func (chat *Chat) SaveSettings(allSettings interface{}) error { serviceID := chat.ctx.getServiceID() _, err := chat.ctx.db.C("chats").UpsertId(chat.ID, bson.M{"$set": bson.M{"settings." + serviceID: allSettings}, "$setOnInsert": bson.M{"createdat": time.Now()}}) if chat.data == nil { chat.data = &chatData{} } ...
[ "func", "(", "chat", "*", "Chat", ")", "SaveSettings", "(", "allSettings", "interface", "{", "}", ")", "error", "{", "serviceID", ":=", "chat", ".", "ctx", ".", "getServiceID", "(", ")", "\n\n", "_", ",", "err", ":=", "chat", ".", "ctx", ".", "db", ...
// SaveSettings save Chat's setting for service
[ "SaveSettings", "save", "Chat", "s", "setting", "for", "service" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L713-L730
train
requilence/integram
data.go
SaveSettings
func (user *User) SaveSettings(allSettings interface{}) error { serviceID := user.ctx.getServiceID() _, err := user.ctx.db.C("users").UpsertId(user.ID, bson.M{"$set": bson.M{"settings." + serviceID: allSettings}, "$setOnInsert": bson.M{"createdat": time.Now()}}) if user.data == nil { user.data = &userData{} } ...
go
func (user *User) SaveSettings(allSettings interface{}) error { serviceID := user.ctx.getServiceID() _, err := user.ctx.db.C("users").UpsertId(user.ID, bson.M{"$set": bson.M{"settings." + serviceID: allSettings}, "$setOnInsert": bson.M{"createdat": time.Now()}}) if user.data == nil { user.data = &userData{} } ...
[ "func", "(", "user", "*", "User", ")", "SaveSettings", "(", "allSettings", "interface", "{", "}", ")", "error", "{", "serviceID", ":=", "user", ".", "ctx", ".", "getServiceID", "(", ")", "\n\n", "_", ",", "err", ":=", "user", ".", "ctx", ".", "db", ...
// SaveSettings save User's setting for service
[ "SaveSettings", "save", "User", "s", "setting", "for", "service" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L733-L748
train
requilence/integram
data.go
ServiceHookToken
func (chat *Chat) ServiceHookToken() string { data, _ := chat.getData() //TODO: test backward compatibility cases for _, hook := range data.Hooks { for _, service := range hook.Services { if service == chat.ctx.ServiceName { return hook.Token } } } token := "c" + rndStr.Get(10) chat.addHook(serviceH...
go
func (chat *Chat) ServiceHookToken() string { data, _ := chat.getData() //TODO: test backward compatibility cases for _, hook := range data.Hooks { for _, service := range hook.Services { if service == chat.ctx.ServiceName { return hook.Token } } } token := "c" + rndStr.Get(10) chat.addHook(serviceH...
[ "func", "(", "chat", "*", "Chat", ")", "ServiceHookToken", "(", ")", "string", "{", "data", ",", "_", ":=", "chat", ".", "getData", "(", ")", "\n", "//TODO: test backward compatibility cases", "for", "_", ",", "hook", ":=", "range", "data", ".", "Hooks", ...
// ServiceHookToken returns Chats's hook token to use in webhook handling
[ "ServiceHookToken", "returns", "Chats", "s", "hook", "token", "to", "use", "in", "webhook", "handling" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L784-L800
train
requilence/integram
data.go
ServiceHookURL
func (user *User) ServiceHookURL() string { return Config.BaseURL + "/" + user.ctx.ServiceName + "/" + user.ServiceHookToken() }
go
func (user *User) ServiceHookURL() string { return Config.BaseURL + "/" + user.ctx.ServiceName + "/" + user.ServiceHookToken() }
[ "func", "(", "user", "*", "User", ")", "ServiceHookURL", "(", ")", "string", "{", "return", "Config", ".", "BaseURL", "+", "\"", "\"", "+", "user", ".", "ctx", ".", "ServiceName", "+", "\"", "\"", "+", "user", ".", "ServiceHookToken", "(", ")", "\n",...
// ServiceHookURL returns User's webhook URL for service to use in webhook handling // Used in case when incoming webhooks despatching on the user behalf to chats
[ "ServiceHookURL", "returns", "User", "s", "webhook", "URL", "for", "service", "to", "use", "in", "webhook", "handling", "Used", "in", "case", "when", "incoming", "webhooks", "despatching", "on", "the", "user", "behalf", "to", "chats" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L804-L806
train
requilence/integram
data.go
ServiceHookURL
func (chat *Chat) ServiceHookURL() string { return Config.BaseURL + "/" + chat.ctx.ServiceName + "/" + chat.ServiceHookToken() }
go
func (chat *Chat) ServiceHookURL() string { return Config.BaseURL + "/" + chat.ctx.ServiceName + "/" + chat.ServiceHookToken() }
[ "func", "(", "chat", "*", "Chat", ")", "ServiceHookURL", "(", ")", "string", "{", "return", "Config", ".", "BaseURL", "+", "\"", "\"", "+", "chat", ".", "ctx", ".", "ServiceName", "+", "\"", "\"", "+", "chat", ".", "ServiceHookToken", "(", ")", "\n",...
// ServiceHookURL returns Chats's webhook URL for service to use in webhook handling // Used in case when user need to put webhook URL to receive notifications to chat
[ "ServiceHookURL", "returns", "Chats", "s", "webhook", "URL", "for", "service", "to", "use", "in", "webhook", "handling", "Used", "in", "case", "when", "user", "need", "to", "put", "webhook", "URL", "to", "receive", "notifications", "to", "chat" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L810-L812
train
requilence/integram
data.go
AddChatToHook
func (user *User) AddChatToHook(chatID int64) error { data, _ := user.getData() token := user.ServiceHookToken() for i, hook := range data.Hooks { if hook.Token == token { for _, service := range hook.Services { if service == user.ctx.ServiceName { for _, existingChatID := range hook.Chats { if ...
go
func (user *User) AddChatToHook(chatID int64) error { data, _ := user.getData() token := user.ServiceHookToken() for i, hook := range data.Hooks { if hook.Token == token { for _, service := range hook.Services { if service == user.ctx.ServiceName { for _, existingChatID := range hook.Chats { if ...
[ "func", "(", "user", "*", "User", ")", "AddChatToHook", "(", "chatID", "int64", ")", "error", "{", "data", ",", "_", ":=", "user", ".", "getData", "(", ")", "\n", "token", ":=", "user", ".", "ServiceHookToken", "(", ")", "\n\n", "for", "i", ",", "h...
// AddChatToHook adds the target chat to user's existing hook
[ "AddChatToHook", "adds", "the", "target", "chat", "to", "user", "s", "existing", "hook" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L815-L839
train
requilence/integram
data.go
SaveSetting
func (chat *Chat) SaveSetting(key string, value interface{}) error { key = strings.ToLower(key) serviceID := chat.ctx.getServiceID() var cd chatData _, err := chat.ctx.db.C("chats").FindId(chat.ID).Select(bson.M{"settings." + serviceID: 1}). Apply( mgo.Change{ Update: bson.M{ "$set": bson.M{"set...
go
func (chat *Chat) SaveSetting(key string, value interface{}) error { key = strings.ToLower(key) serviceID := chat.ctx.getServiceID() var cd chatData _, err := chat.ctx.db.C("chats").FindId(chat.ID).Select(bson.M{"settings." + serviceID: 1}). Apply( mgo.Change{ Update: bson.M{ "$set": bson.M{"set...
[ "func", "(", "chat", "*", "Chat", ")", "SaveSetting", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "key", "=", "strings", ".", "ToLower", "(", "key", ")", "\n", "serviceID", ":=", "chat", ".", "ctx", ".", "getServiceI...
// SaveSetting sets Chat's setting for service with specific key
[ "SaveSetting", "sets", "Chat", "s", "setting", "for", "service", "with", "specific", "key" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L895-L917
train
requilence/integram
data.go
SaveSetting
func (user *User) SaveSetting(key string, value interface{}) error { if user.ID == 0 { return errors.New("SaveSetting: user is empty") } key = strings.ToLower(key) serviceID := user.ctx.getServiceID() var ud userData _, err := user.ctx.db.C("users").FindId(user.ID).Select(bson.M{"settings." + serviceID: 1})....
go
func (user *User) SaveSetting(key string, value interface{}) error { if user.ID == 0 { return errors.New("SaveSetting: user is empty") } key = strings.ToLower(key) serviceID := user.ctx.getServiceID() var ud userData _, err := user.ctx.db.C("users").FindId(user.ID).Select(bson.M{"settings." + serviceID: 1})....
[ "func", "(", "user", "*", "User", ")", "SaveSetting", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "if", "user", ".", "ID", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", ...
// SaveSetting sets User's setting for service with specific key
[ "SaveSetting", "sets", "User", "s", "setting", "for", "service", "with", "specific", "key" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L920-L947
train
requilence/integram
data.go
AuthTempToken
func (user *User) AuthTempToken() string { host := user.ctx.ServiceBaseURL.Host if host == "" { host = user.ctx.Service().DefaultBaseURL.Host } serviceBaseURL := user.ctx.ServiceBaseURL.String() if serviceBaseURL == "" { serviceBaseURL = user.ctx.Service().DefaultBaseURL.String() } ps, _ := user.protected...
go
func (user *User) AuthTempToken() string { host := user.ctx.ServiceBaseURL.Host if host == "" { host = user.ctx.Service().DefaultBaseURL.Host } serviceBaseURL := user.ctx.ServiceBaseURL.String() if serviceBaseURL == "" { serviceBaseURL = user.ctx.Service().DefaultBaseURL.String() } ps, _ := user.protected...
[ "func", "(", "user", "*", "User", ")", "AuthTempToken", "(", ")", "string", "{", "host", ":=", "user", ".", "ctx", ".", "ServiceBaseURL", ".", "Host", "\n", "if", "host", "==", "\"", "\"", "{", "host", "=", "user", ".", "ctx", ".", "Service", "(", ...
// AuthTempToken returns Auth token used in OAuth process to associate TG user with OAuth creditianals
[ "AuthTempToken", "returns", "Auth", "token", "used", "in", "OAuth", "process", "to", "associate", "TG", "user", "with", "OAuth", "creditianals" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L950-L988
train
requilence/integram
data.go
OauthRedirectURL
func (user *User) OauthRedirectURL() string { providerID := user.ctx.OAuthProvider().internalID() if providerID == user.ctx.ServiceName { return fmt.Sprintf("%s/auth/%s", Config.BaseURL, user.ctx.ServiceName) } return fmt.Sprintf("%s/auth/%s/%s", Config.BaseURL, user.ctx.ServiceName, providerID) }
go
func (user *User) OauthRedirectURL() string { providerID := user.ctx.OAuthProvider().internalID() if providerID == user.ctx.ServiceName { return fmt.Sprintf("%s/auth/%s", Config.BaseURL, user.ctx.ServiceName) } return fmt.Sprintf("%s/auth/%s/%s", Config.BaseURL, user.ctx.ServiceName, providerID) }
[ "func", "(", "user", "*", "User", ")", "OauthRedirectURL", "(", ")", "string", "{", "providerID", ":=", "user", ".", "ctx", ".", "OAuthProvider", "(", ")", ".", "internalID", "(", ")", "\n", "if", "providerID", "==", "user", ".", "ctx", ".", "ServiceNa...
// OauthRedirectURL used in OAuth process as returning URL
[ "OauthRedirectURL", "used", "in", "OAuth", "process", "as", "returning", "URL" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L991-L998
train
requilence/integram
data.go
OauthInitURL
func (user *User) OauthInitURL() string { authTempToken := user.AuthTempToken() s := user.ctx.Service() if authTempToken == "" { user.ctx.Log().Error("authTempToken is empty") return "" } if s.DefaultOAuth2 != nil { provider := user.ctx.OAuthProvider() return provider.OAuth2Client(user.ctx).AuthCodeURL(au...
go
func (user *User) OauthInitURL() string { authTempToken := user.AuthTempToken() s := user.ctx.Service() if authTempToken == "" { user.ctx.Log().Error("authTempToken is empty") return "" } if s.DefaultOAuth2 != nil { provider := user.ctx.OAuthProvider() return provider.OAuth2Client(user.ctx).AuthCodeURL(au...
[ "func", "(", "user", "*", "User", ")", "OauthInitURL", "(", ")", "string", "{", "authTempToken", ":=", "user", ".", "AuthTempToken", "(", ")", "\n", "s", ":=", "user", ".", "ctx", ".", "Service", "(", ")", "\n", "if", "authTempToken", "==", "\"", "\"...
// OauthInitURL used in OAuth process as returning URL
[ "OauthInitURL", "used", "in", "OAuth", "process", "as", "returning", "URL" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L1001-L1017
train
requilence/integram
data.go
OAuthHTTPClient
func (user *User) OAuthHTTPClient() *http.Client { ps, _ := user.protectedSettings() if ps == nil { return nil } if ps.OAuthToken == "" { return nil } if user.ctx.Service().DefaultOAuth2 != nil { ts := user.ctx.OAuthProvider().OAuth2Client(user.ctx).TokenSource(oauth2.NoContext, &oauth2.Token{AccessToke...
go
func (user *User) OAuthHTTPClient() *http.Client { ps, _ := user.protectedSettings() if ps == nil { return nil } if ps.OAuthToken == "" { return nil } if user.ctx.Service().DefaultOAuth2 != nil { ts := user.ctx.OAuthProvider().OAuth2Client(user.ctx).TokenSource(oauth2.NoContext, &oauth2.Token{AccessToke...
[ "func", "(", "user", "*", "User", ")", "OAuthHTTPClient", "(", ")", "*", "http", ".", "Client", "{", "ps", ",", "_", ":=", "user", ".", "protectedSettings", "(", ")", "\n\n", "if", "ps", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", ...
// OAuthHTTPClient returns HTTP client with Bearer authorization headers
[ "OAuthHTTPClient", "returns", "HTTP", "client", "with", "Bearer", "authorization", "headers" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L1024-L1066
train
requilence/integram
data.go
OAuthToken
func (user *User) OAuthToken() string { // todo: oauthtoken per host? /* host := user.ctx.ServiceBaseURL.Host if host == "" { host = user.ctx.Service().DefaultBaseURL.Host } */ ps, _ := user.protectedSettings() if ps != nil { if ps.OAuthExpireDate != nil && ps.OAuthExpireDate.Before(time.Now().Add(tim...
go
func (user *User) OAuthToken() string { // todo: oauthtoken per host? /* host := user.ctx.ServiceBaseURL.Host if host == "" { host = user.ctx.Service().DefaultBaseURL.Host } */ ps, _ := user.protectedSettings() if ps != nil { if ps.OAuthExpireDate != nil && ps.OAuthExpireDate.Before(time.Now().Add(tim...
[ "func", "(", "user", "*", "User", ")", "OAuthToken", "(", ")", "string", "{", "// todo: oauthtoken per host?", "/*\n\t\thost := user.ctx.ServiceBaseURL.Host\n\n\t\tif host == \"\" {\n\t\t\thost = user.ctx.Service().DefaultBaseURL.Host\n\t\t}\n\t*/", "ps", ",", "_", ":=", "user", ...
// OAuthToken returns OAuthToken for service
[ "OAuthToken", "returns", "OAuthToken", "for", "service" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L1083-L1125
train
requilence/integram
data.go
ResetOAuthToken
func (user *User) ResetOAuthToken() error { err := user.saveProtectedSetting("OAuthToken", "") if err != nil { user.ctx.Log().WithError(err).Error("ResetOAuthToken error") } return err }
go
func (user *User) ResetOAuthToken() error { err := user.saveProtectedSetting("OAuthToken", "") if err != nil { user.ctx.Log().WithError(err).Error("ResetOAuthToken error") } return err }
[ "func", "(", "user", "*", "User", ")", "ResetOAuthToken", "(", ")", "error", "{", "err", ":=", "user", ".", "saveProtectedSetting", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "user", ".", "ctx", ".", "Log", "(", "...
// ResetOAuthToken reset OAuthToken for service
[ "ResetOAuthToken", "reset", "OAuthToken", "for", "service" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L1128-L1134
train
requilence/integram
data.go
WebPreview
func (c *Context) WebPreview(title string, headline string, text string, serviceURL string, imageURL string) (WebPreviewURL string) { token := rndStr.Get(10) if title == "" { title = c.Service().NameToPrint c.Log().WithField("token", token).Warn("webPreview: title is empty") } if headline == "" { c.Log().Wit...
go
func (c *Context) WebPreview(title string, headline string, text string, serviceURL string, imageURL string) (WebPreviewURL string) { token := rndStr.Get(10) if title == "" { title = c.Service().NameToPrint c.Log().WithField("token", token).Warn("webPreview: title is empty") } if headline == "" { c.Log().Wit...
[ "func", "(", "c", "*", "Context", ")", "WebPreview", "(", "title", "string", ",", "headline", "string", ",", "text", "string", ",", "serviceURL", "string", ",", "imageURL", "string", ")", "(", "WebPreviewURL", "string", ")", "{", "token", ":=", "rndStr", ...
// WebPreview generate fake webpreview and store it in DB. Telegram will resolve it as we need
[ "WebPreview", "generate", "fake", "webpreview", "and", "store", "it", "in", "DB", ".", "Telegram", "will", "resolve", "it", "as", "we", "need" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/data.go#L1188-L1233
train
requilence/integram
context.go
SetServiceBaseURL
func (c *Context) SetServiceBaseURL(domainOrURL string) { u, _ := getBaseURL(domainOrURL) if u != nil && u.Host != "" { c.ServiceBaseURL = *u } else if domainOrURL != "" { c.ServiceBaseURL = url.URL{Scheme: "https", Host: domainOrURL} } else { c.Log().Error("Can't use SetServiceHostFromURL with empty arg") ...
go
func (c *Context) SetServiceBaseURL(domainOrURL string) { u, _ := getBaseURL(domainOrURL) if u != nil && u.Host != "" { c.ServiceBaseURL = *u } else if domainOrURL != "" { c.ServiceBaseURL = url.URL{Scheme: "https", Host: domainOrURL} } else { c.Log().Error("Can't use SetServiceHostFromURL with empty arg") ...
[ "func", "(", "c", "*", "Context", ")", "SetServiceBaseURL", "(", "domainOrURL", "string", ")", "{", "u", ",", "_", ":=", "getBaseURL", "(", "domainOrURL", ")", "\n\n", "if", "u", "!=", "nil", "&&", "u", ".", "Host", "!=", "\"", "\"", "{", "c", ".",...
// SetServiceBaseURL set the baseURL for the current request. Useful when service can be self-hosted. The actual service URL can be found in the incoming webhook
[ "SetServiceBaseURL", "set", "the", "baseURL", "for", "the", "current", "request", ".", "Useful", "when", "service", "can", "be", "self", "-", "hosted", ".", "The", "actual", "service", "URL", "can", "be", "found", "in", "the", "incoming", "webhook" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L68-L78
train
requilence/integram
context.go
SaveOAuthProvider
func (c *Context) SaveOAuthProvider(baseURL url.URL, id string, secret string) (*OAuthProvider, error) { if id == "" || secret == "" { return nil, errors.New("id and secret must not be empty") } baseURL.Host = strings.ToLower(baseURL.Host) provider := OAuthProvider{BaseURL: baseURL, ID: id, Secret: secret, Serv...
go
func (c *Context) SaveOAuthProvider(baseURL url.URL, id string, secret string) (*OAuthProvider, error) { if id == "" || secret == "" { return nil, errors.New("id and secret must not be empty") } baseURL.Host = strings.ToLower(baseURL.Host) provider := OAuthProvider{BaseURL: baseURL, ID: id, Secret: secret, Serv...
[ "func", "(", "c", "*", "Context", ")", "SaveOAuthProvider", "(", "baseURL", "url", ".", "URL", ",", "id", "string", ",", "secret", "string", ")", "(", "*", "OAuthProvider", ",", "error", ")", "{", "if", "id", "==", "\"", "\"", "||", "secret", "==", ...
// SaveOAuthProvider add the OAuth client to DB. Useful when the new OAuth provider registred for self-hosted services
[ "SaveOAuthProvider", "add", "the", "OAuth", "client", "to", "DB", ".", "Useful", "when", "the", "new", "OAuth", "provider", "registred", "for", "self", "-", "hosted", "services" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L81-L93
train
requilence/integram
context.go
OAuthProvider
func (c *Context) OAuthProvider() *OAuthProvider { service := c.Service() if c.ServiceBaseURL.Host == "" || c.ServiceBaseURL.Host == service.DefaultBaseURL.Host { return service.DefaultOAuthProvider() } else if c.ServiceBaseURL.Host != "" { p, _ := findOauthProviderByHost(c.db, c.ServiceBaseURL.Host) if p ==...
go
func (c *Context) OAuthProvider() *OAuthProvider { service := c.Service() if c.ServiceBaseURL.Host == "" || c.ServiceBaseURL.Host == service.DefaultBaseURL.Host { return service.DefaultOAuthProvider() } else if c.ServiceBaseURL.Host != "" { p, _ := findOauthProviderByHost(c.db, c.ServiceBaseURL.Host) if p ==...
[ "func", "(", "c", "*", "Context", ")", "OAuthProvider", "(", ")", "*", "OAuthProvider", "{", "service", ":=", "c", ".", "Service", "(", ")", "\n", "if", "c", ".", "ServiceBaseURL", ".", "Host", "==", "\"", "\"", "||", "c", ".", "ServiceBaseURL", ".",...
// OAuthProvider details. Useful for services that can be installed on your own side
[ "OAuthProvider", "details", ".", "Useful", "for", "services", "that", "can", "be", "installed", "on", "your", "own", "side" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L96-L116
train
requilence/integram
context.go
OAuth1Client
func (o *OAuthProvider) OAuth1Client(c *Context) *oauth.Consumer { if o.ID == "" { log.Error(errors.New("Can't get OAuth1Client – ID not set")) return nil } service := c.Service() config := service.DefaultOAuth1 if config.AccessTokenReceiver == nil { log.Error(errors.New("Can't get OAuth1Client – AccessTo...
go
func (o *OAuthProvider) OAuth1Client(c *Context) *oauth.Consumer { if o.ID == "" { log.Error(errors.New("Can't get OAuth1Client – ID not set")) return nil } service := c.Service() config := service.DefaultOAuth1 if config.AccessTokenReceiver == nil { log.Error(errors.New("Can't get OAuth1Client – AccessTo...
[ "func", "(", "o", "*", "OAuthProvider", ")", "OAuth1Client", "(", "c", "*", "Context", ")", "*", "oauth", ".", "Consumer", "{", "if", "o", ".", "ID", "==", "\"", "\"", "{", "log", ".", "Error", "(", "errors", ".", "New", "(", "\"", ")", "", "",...
// OAuth1Client returns oauth.Consumer using OAuthProvider details
[ "OAuth1Client", "returns", "oauth", ".", "Consumer", "using", "OAuthProvider", "details" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L134-L167
train
requilence/integram
context.go
OAuth2Client
func (o *OAuthProvider) OAuth2Client(c *Context) *oauth2.Config { if o.ID == "" { return nil } service := c.Service() if service.DefaultOAuth2 == nil { return nil } config := service.DefaultOAuth2.Config config.ClientID = o.ID config.ClientSecret = o.Secret if c.User.ID != 0 { config.RedirectURL = c...
go
func (o *OAuthProvider) OAuth2Client(c *Context) *oauth2.Config { if o.ID == "" { return nil } service := c.Service() if service.DefaultOAuth2 == nil { return nil } config := service.DefaultOAuth2.Config config.ClientID = o.ID config.ClientSecret = o.Secret if c.User.ID != 0 { config.RedirectURL = c...
[ "func", "(", "o", "*", "OAuthProvider", ")", "OAuth2Client", "(", "c", "*", "Context", ")", "*", "oauth2", ".", "Config", "{", "if", "o", ".", "ID", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "service", ":=", "c", ".", "Service", ...
// OAuth2Client returns oauth2.Config using OAuthProvider details
[ "OAuth2Client", "returns", "oauth2", ".", "Config", "using", "OAuthProvider", "details" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L170-L196
train
requilence/integram
context.go
Param
func (wc *WebhookContext) Param(s string) string { return wc.gin.Param(s) }
go
func (wc *WebhookContext) Param(s string) string { return wc.gin.Param(s) }
[ "func", "(", "wc", "*", "WebhookContext", ")", "Param", "(", "s", "string", ")", "string", "{", "return", "wc", ".", "gin", ".", "Param", "(", "s", ")", "\n", "}" ]
// Param return param from url
[ "Param", "return", "param", "from", "url" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L213-L215
train
requilence/integram
context.go
Headers
func (wc *WebhookContext) Headers() map[string][]string { return map[string][]string(wc.gin.Request.Header) }
go
func (wc *WebhookContext) Headers() map[string][]string { return map[string][]string(wc.gin.Request.Header) }
[ "func", "(", "wc", "*", "WebhookContext", ")", "Headers", "(", ")", "map", "[", "string", "]", "[", "]", "string", "{", "return", "map", "[", "string", "]", "[", "]", "string", "(", "wc", ".", "gin", ".", "Request", ".", "Header", ")", "\n", "}" ...
// Headers returns the headers of request
[ "Headers", "returns", "the", "headers", "of", "request" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L239-L241
train
requilence/integram
context.go
Redirect
func (wc *WebhookContext) Redirect(code int, s string) { wc.gin.Redirect(code, s) }
go
func (wc *WebhookContext) Redirect(code int, s string) { wc.gin.Redirect(code, s) }
[ "func", "(", "wc", "*", "WebhookContext", ")", "Redirect", "(", "code", "int", ",", "s", "string", ")", "{", "wc", ".", "gin", ".", "Redirect", "(", "code", ",", "s", ")", "\n", "}" ]
// Redirect send the Location header
[ "Redirect", "send", "the", "Location", "header" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L254-L256
train
requilence/integram
context.go
KeyboardAnswer
func (c *Context) KeyboardAnswer() (data string, buttonText string) { keyboard, err := c.keyboard() if err != nil || keyboard.ChatID == 0 { log.WithError(err).Error("Can't get stored keyboard") return } // In group chat keyboard answer always include msg_id of original message that generate this keyboard if ...
go
func (c *Context) KeyboardAnswer() (data string, buttonText string) { keyboard, err := c.keyboard() if err != nil || keyboard.ChatID == 0 { log.WithError(err).Error("Can't get stored keyboard") return } // In group chat keyboard answer always include msg_id of original message that generate this keyboard if ...
[ "func", "(", "c", "*", "Context", ")", "KeyboardAnswer", "(", ")", "(", "data", "string", ",", "buttonText", "string", ")", "{", "keyboard", ",", "err", ":=", "c", ".", "keyboard", "(", ")", "\n\n", "if", "err", "!=", "nil", "||", "keyboard", ".", ...
// KeyboardAnswer retrieve the data related to pressed button // buttonText will be returned only in case this button relates to the one in db for this chat
[ "KeyboardAnswer", "retrieve", "the", "data", "related", "to", "pressed", "button", "buttonText", "will", "be", "returned", "only", "in", "case", "this", "button", "relates", "to", "the", "one", "in", "db", "for", "this", "chat" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L260-L286
train
requilence/integram
context.go
keyboard
func (c *Context) keyboard() (chatKeyboard, error) { udata, _ := c.User.getData() chatID := c.Chat.ID for _, kb := range udata.KeyboardPerChat { if kb.ChatID == chatID && kb.BotID == c.Bot().ID { return kb, nil } } cdata, _ := c.Chat.getData() for _, kb := range cdata.KeyboardPerBot { if kb.ChatID =...
go
func (c *Context) keyboard() (chatKeyboard, error) { udata, _ := c.User.getData() chatID := c.Chat.ID for _, kb := range udata.KeyboardPerChat { if kb.ChatID == chatID && kb.BotID == c.Bot().ID { return kb, nil } } cdata, _ := c.Chat.getData() for _, kb := range cdata.KeyboardPerBot { if kb.ChatID =...
[ "func", "(", "c", "*", "Context", ")", "keyboard", "(", ")", "(", "chatKeyboard", ",", "error", ")", "{", "udata", ",", "_", ":=", "c", ".", "User", ".", "getData", "(", ")", "\n", "chatID", ":=", "c", ".", "Chat", ".", "ID", "\n\n", "for", "_"...
// Keyboard retrieve keyboard for the current chat if set otherwise empty keyboard is returned
[ "Keyboard", "retrieve", "keyboard", "for", "the", "current", "chat", "if", "set", "otherwise", "empty", "keyboard", "is", "returned" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L351-L372
train
requilence/integram
context.go
Log
func (c *Context) Log() *log.Entry { fields := log.Fields{"service": c.ServiceName} if Config.Debug { pc := make([]uintptr, 10) runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) fields["file"], fields["line"] = f.FileLine(pc[0]) fields["func"] = f.Name() } if c.User.ID > 0 { fields["user"] = c.User...
go
func (c *Context) Log() *log.Entry { fields := log.Fields{"service": c.ServiceName} if Config.Debug { pc := make([]uintptr, 10) runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) fields["file"], fields["line"] = f.FileLine(pc[0]) fields["func"] = f.Name() } if c.User.ID > 0 { fields["user"] = c.User...
[ "func", "(", "c", "*", "Context", ")", "Log", "(", ")", "*", "log", ".", "Entry", "{", "fields", ":=", "log", ".", "Fields", "{", "\"", "\"", ":", "c", ".", "ServiceName", "}", "\n\n", "if", "Config", ".", "Debug", "{", "pc", ":=", "make", "(",...
// Log creates the logrus entry and attach corresponding info from the context
[ "Log", "creates", "the", "logrus", "entry", "and", "attach", "corresponding", "info", "from", "the", "context" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L375-L424
train
requilence/integram
context.go
Service
func (c *Context) Service() *Service { s, _ := serviceByName(c.ServiceName) return s }
go
func (c *Context) Service() *Service { s, _ := serviceByName(c.ServiceName) return s }
[ "func", "(", "c", "*", "Context", ")", "Service", "(", ")", "*", "Service", "{", "s", ",", "_", ":=", "serviceByName", "(", "c", ".", "ServiceName", ")", "\n", "return", "s", "\n", "}" ]
// Service related to the current context
[ "Service", "related", "to", "the", "current", "context" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L432-L435
train
requilence/integram
context.go
EditPressedMessageText
func (c *Context) EditPressedMessageText(text string) error { if c.Callback == nil { return errors.New("EditPressedMessageText: Callback is not presented") } return c.EditMessageText(c.Callback.Message, text) }
go
func (c *Context) EditPressedMessageText(text string) error { if c.Callback == nil { return errors.New("EditPressedMessageText: Callback is not presented") } return c.EditMessageText(c.Callback.Message, text) }
[ "func", "(", "c", "*", "Context", ")", "EditPressedMessageText", "(", "text", "string", ")", "error", "{", "if", "c", ".", "Callback", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "c", ".", "E...
// EditPressedMessageText edit the text in the msg where user taped it in case this request is triggered by inlineButton callback
[ "EditPressedMessageText", "edit", "the", "text", "in", "the", "msg", "where", "user", "taped", "it", "in", "case", "this", "request", "is", "triggered", "by", "inlineButton", "callback" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L443-L449
train
requilence/integram
context.go
EditPressedMessageTextAndInlineKeyboard
func (c *Context) EditPressedMessageTextAndInlineKeyboard(text string, kb InlineKeyboard) error { if c.Callback == nil { return errors.New("EditPressedMessageTextAndInlineKeyboard: Callback is not presented") } return c.EditMessageTextAndInlineKeyboard(c.Callback.Message, c.Callback.Message.InlineKeyboardMarkup.S...
go
func (c *Context) EditPressedMessageTextAndInlineKeyboard(text string, kb InlineKeyboard) error { if c.Callback == nil { return errors.New("EditPressedMessageTextAndInlineKeyboard: Callback is not presented") } return c.EditMessageTextAndInlineKeyboard(c.Callback.Message, c.Callback.Message.InlineKeyboardMarkup.S...
[ "func", "(", "c", "*", "Context", ")", "EditPressedMessageTextAndInlineKeyboard", "(", "text", "string", ",", "kb", "InlineKeyboard", ")", "error", "{", "if", "c", ".", "Callback", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "...
// EditPressedMessageTextAndInlineKeyboard edit the text and inline keyboard in the msg where user taped it in case this request is triggered by inlineButton callback
[ "EditPressedMessageTextAndInlineKeyboard", "edit", "the", "text", "and", "inline", "keyboard", "in", "the", "msg", "where", "user", "taped", "it", "in", "case", "this", "request", "is", "triggered", "by", "inlineButton", "callback" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L452-L458
train
requilence/integram
context.go
EditPressedInlineKeyboard
func (c *Context) EditPressedInlineKeyboard(kb InlineKeyboard) error { if c.Callback == nil { return errors.New("EditPressedInlineKeyboard: Callback is not presented") } return c.EditInlineKeyboard(c.Callback.Message, c.Callback.Message.InlineKeyboardMarkup.State, kb) }
go
func (c *Context) EditPressedInlineKeyboard(kb InlineKeyboard) error { if c.Callback == nil { return errors.New("EditPressedInlineKeyboard: Callback is not presented") } return c.EditInlineKeyboard(c.Callback.Message, c.Callback.Message.InlineKeyboardMarkup.State, kb) }
[ "func", "(", "c", "*", "Context", ")", "EditPressedInlineKeyboard", "(", "kb", "InlineKeyboard", ")", "error", "{", "if", "c", ".", "Callback", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "c", ...
// EditPressedInlineKeyboard edit the inline keyboard in the msg where user taped it in case this request is triggered by inlineButton callback
[ "EditPressedInlineKeyboard", "edit", "the", "inline", "keyboard", "in", "the", "msg", "where", "user", "taped", "it", "in", "case", "this", "request", "is", "triggered", "by", "inlineButton", "callback" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L461-L467
train
requilence/integram
context.go
EditPressedInlineButton
func (c *Context) EditPressedInlineButton(newState int, newText string) error { log.WithField("newText", newText).WithField("newState", newState).Info("EditPressedInlineButton") if c.Callback == nil { return errors.New("EditPressedInlineButton: Callback is not presented") } return c.EditInlineStateButton(c.Callb...
go
func (c *Context) EditPressedInlineButton(newState int, newText string) error { log.WithField("newText", newText).WithField("newState", newState).Info("EditPressedInlineButton") if c.Callback == nil { return errors.New("EditPressedInlineButton: Callback is not presented") } return c.EditInlineStateButton(c.Callb...
[ "func", "(", "c", "*", "Context", ")", "EditPressedInlineButton", "(", "newState", "int", ",", "newText", "string", ")", "error", "{", "log", ".", "WithField", "(", "\"", "\"", ",", "newText", ")", ".", "WithField", "(", "\"", "\"", ",", "newState", ")...
// EditPressedInlineButton edit the text and state of pressed inline button in case this request is triggered by inlineButton callback
[ "EditPressedInlineButton", "edit", "the", "text", "and", "state", "of", "pressed", "inline", "button", "in", "case", "this", "request", "is", "triggered", "by", "inlineButton", "callback" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L470-L477
train
requilence/integram
context.go
EditMessageText
func (c *Context) EditMessageText(om *OutgoingMessage, text string) error { if om == nil { return errors.New("Empty message provided") } bot := c.Bot() if om.ParseMode == "HTML" { textCleared, err := sanitize.HTMLAllowing(text, []string{"a", "b", "strong", "i", "em", "a", "code", "pre"}, []string{"href"}) i...
go
func (c *Context) EditMessageText(om *OutgoingMessage, text string) error { if om == nil { return errors.New("Empty message provided") } bot := c.Bot() if om.ParseMode == "HTML" { textCleared, err := sanitize.HTMLAllowing(text, []string{"a", "b", "strong", "i", "em", "a", "code", "pre"}, []string{"href"}) i...
[ "func", "(", "c", "*", "Context", ")", "EditMessageText", "(", "om", "*", "OutgoingMessage", ",", "text", "string", ")", "error", "{", "if", "om", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "bot", ":=...
// EditMessageText edit the text of message previously sent by the bot
[ "EditMessageText", "edit", "the", "text", "of", "message", "previously", "sent", "by", "the", "bot" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L480-L526
train
requilence/integram
context.go
EditMessagesTextWithEventID
func (c *Context) EditMessagesTextWithEventID(eventID string, text string) (edited int, err error) { var messages []OutgoingMessage //update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages c.db.C("messages").Find(bson.M{"botid": c.Bot().ID, "eventid": eventID}).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&m...
go
func (c *Context) EditMessagesTextWithEventID(eventID string, text string) (edited int, err error) { var messages []OutgoingMessage //update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages c.db.C("messages").Find(bson.M{"botid": c.Bot().ID, "eventid": eventID}).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&m...
[ "func", "(", "c", "*", "Context", ")", "EditMessagesTextWithEventID", "(", "eventID", "string", ",", "text", "string", ")", "(", "edited", "int", ",", "err", "error", ")", "{", "var", "messages", "[", "]", "OutgoingMessage", "\n", "//update MAX_MSGS_TO_UPDATE_...
// EditMessagesTextWithEventID edit the last MaxMsgsToUpdateWithEventID messages' text with the corresponding eventID in ALL chats
[ "EditMessagesTextWithEventID", "edit", "the", "last", "MaxMsgsToUpdateWithEventID", "messages", "text", "with", "the", "corresponding", "eventID", "in", "ALL", "chats" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L529-L542
train
requilence/integram
context.go
EditMessageTextWithMessageID
func (c *Context) EditMessageTextWithMessageID(msgID bson.ObjectId, text string) (edited int, err error) { var message OutgoingMessage c.db.C("messages").Find(bson.M{"_id": msgID, "botid": c.Bot().ID}).One(&message) err = c.EditMessageText(&message, text) if err != nil { c.Log().WithError(err).WithField("msgid",...
go
func (c *Context) EditMessageTextWithMessageID(msgID bson.ObjectId, text string) (edited int, err error) { var message OutgoingMessage c.db.C("messages").Find(bson.M{"_id": msgID, "botid": c.Bot().ID}).One(&message) err = c.EditMessageText(&message, text) if err != nil { c.Log().WithError(err).WithField("msgid",...
[ "func", "(", "c", "*", "Context", ")", "EditMessageTextWithMessageID", "(", "msgID", "bson", ".", "ObjectId", ",", "text", "string", ")", "(", "edited", "int", ",", "err", "error", ")", "{", "var", "message", "OutgoingMessage", "\n\n", "c", ".", "db", "....
// EditMessagesTextWithMessageID edit the one message text with by message BSON ID
[ "EditMessagesTextWithMessageID", "edit", "the", "one", "message", "text", "with", "by", "message", "BSON", "ID" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L545-L557
train
requilence/integram
context.go
EditMessagesWithEventID
func (c *Context) EditMessagesWithEventID(eventID string, fromState string, text string, kb InlineKeyboard) (edited int, err error) { var messages []OutgoingMessage f := bson.M{"botid": c.Bot().ID, "eventid": eventID} if fromState != "" { f["inlinekeyboardmarkup.state"] = fromState } //update MAX_MSGS_TO_UPDATE...
go
func (c *Context) EditMessagesWithEventID(eventID string, fromState string, text string, kb InlineKeyboard) (edited int, err error) { var messages []OutgoingMessage f := bson.M{"botid": c.Bot().ID, "eventid": eventID} if fromState != "" { f["inlinekeyboardmarkup.state"] = fromState } //update MAX_MSGS_TO_UPDATE...
[ "func", "(", "c", "*", "Context", ")", "EditMessagesWithEventID", "(", "eventID", "string", ",", "fromState", "string", ",", "text", "string", ",", "kb", "InlineKeyboard", ")", "(", "edited", "int", ",", "err", "error", ")", "{", "var", "messages", "[", ...
// EditMessagesWithEventID edit the last MaxMsgsToUpdateWithEventID messages' text and inline keyboard with the corresponding eventID in ALL chats
[ "EditMessagesWithEventID", "edit", "the", "last", "MaxMsgsToUpdateWithEventID", "messages", "text", "and", "inline", "keyboard", "with", "the", "corresponding", "eventID", "in", "ALL", "chats" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L560-L578
train
requilence/integram
context.go
DeleteMessagesWithEventID
func (c *Context) DeleteMessagesWithEventID(eventID string) (deleted int, err error) { var messages []OutgoingMessage f := bson.M{"botid": c.Bot().ID, "eventid": eventID} //update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messag...
go
func (c *Context) DeleteMessagesWithEventID(eventID string) (deleted int, err error) { var messages []OutgoingMessage f := bson.M{"botid": c.Bot().ID, "eventid": eventID} //update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messag...
[ "func", "(", "c", "*", "Context", ")", "DeleteMessagesWithEventID", "(", "eventID", "string", ")", "(", "deleted", "int", ",", "err", "error", ")", "{", "var", "messages", "[", "]", "OutgoingMessage", "\n", "f", ":=", "bson", ".", "M", "{", "\"", "\"",...
// DeleteMessagesWithEventID deletes the last MaxMsgsToUpdateWithEventID messages' text and inline keyboard with the corresponding eventID in ALL chats
[ "DeleteMessagesWithEventID", "deletes", "the", "last", "MaxMsgsToUpdateWithEventID", "messages", "text", "and", "inline", "keyboard", "with", "the", "corresponding", "eventID", "in", "ALL", "chats" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L581-L596
train
requilence/integram
context.go
DeleteMessage
func (c *Context) DeleteMessage(om *OutgoingMessage) error { bot := c.Bot() if om.MsgID != 0 { log.WithField("msgID", om.MsgID).Debug("DeleteMessage") } else { om.ChatID = 0 log.WithField("inlineMsgID", om.InlineMsgID).Debug("DeleteMessage") } var msg OutgoingMessage var ci *mgo.ChangeInfo var err error ...
go
func (c *Context) DeleteMessage(om *OutgoingMessage) error { bot := c.Bot() if om.MsgID != 0 { log.WithField("msgID", om.MsgID).Debug("DeleteMessage") } else { om.ChatID = 0 log.WithField("inlineMsgID", om.InlineMsgID).Debug("DeleteMessage") } var msg OutgoingMessage var ci *mgo.ChangeInfo var err error ...
[ "func", "(", "c", "*", "Context", ")", "DeleteMessage", "(", "om", "*", "OutgoingMessage", ")", "error", "{", "bot", ":=", "c", ".", "Bot", "(", ")", "\n", "if", "om", ".", "MsgID", "!=", "0", "{", "log", ".", "WithField", "(", "\"", "\"", ",", ...
// DeleteMessage deletes the outgoing message's text and inline keyboard
[ "DeleteMessage", "deletes", "the", "outgoing", "message", "s", "text", "and", "inline", "keyboard" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L599-L648
train
requilence/integram
context.go
EditInlineKeyboard
func (c *Context) EditInlineKeyboard(om *OutgoingMessage, fromState string, kb InlineKeyboard) error { bot := c.Bot() if om.MsgID != 0 { log.WithField("msgID", om.MsgID).Debug("EditMessageTextAndInlineKeyboard") } else { om.ChatID = 0 log.WithField("inlineMsgID", om.InlineMsgID).Debug("EditMessageTextAndInlin...
go
func (c *Context) EditInlineKeyboard(om *OutgoingMessage, fromState string, kb InlineKeyboard) error { bot := c.Bot() if om.MsgID != 0 { log.WithField("msgID", om.MsgID).Debug("EditMessageTextAndInlineKeyboard") } else { om.ChatID = 0 log.WithField("inlineMsgID", om.InlineMsgID).Debug("EditMessageTextAndInlin...
[ "func", "(", "c", "*", "Context", ")", "EditInlineKeyboard", "(", "om", "*", "OutgoingMessage", ",", "fromState", "string", ",", "kb", "InlineKeyboard", ")", "error", "{", "bot", ":=", "c", ".", "Bot", "(", ")", "\n", "if", "om", ".", "MsgID", "!=", ...
// EditInlineKeyboard edit the outgoing message's inline keyboard
[ "EditInlineKeyboard", "edit", "the", "outgoing", "message", "s", "inline", "keyboard" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L732-L780
train
requilence/integram
context.go
EditInlineButton
func (c *Context) EditInlineButton(om *OutgoingMessage, kbState string, buttonData string, newButtonText string) error { return c.EditInlineStateButton(om, kbState, 0, buttonData, 0, newButtonText) }
go
func (c *Context) EditInlineButton(om *OutgoingMessage, kbState string, buttonData string, newButtonText string) error { return c.EditInlineStateButton(om, kbState, 0, buttonData, 0, newButtonText) }
[ "func", "(", "c", "*", "Context", ")", "EditInlineButton", "(", "om", "*", "OutgoingMessage", ",", "kbState", "string", ",", "buttonData", "string", ",", "newButtonText", "string", ")", "error", "{", "return", "c", ".", "EditInlineStateButton", "(", "om", ",...
// EditInlineButton edit the outgoing message's inline button
[ "EditInlineButton", "edit", "the", "outgoing", "message", "s", "inline", "button" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L783-L786
train
requilence/integram
context.go
EditInlineStateButton
func (c *Context) EditInlineStateButton(om *OutgoingMessage, kbState string, oldButtonState int, buttonData string, newButtonState int, newButtonText string) error { if oldButtonState > 9 || oldButtonState < 0 { c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – ol...
go
func (c *Context) EditInlineStateButton(om *OutgoingMessage, kbState string, oldButtonState int, buttonData string, newButtonState int, newButtonText string) error { if oldButtonState > 9 || oldButtonState < 0 { c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – ol...
[ "func", "(", "c", "*", "Context", ")", "EditInlineStateButton", "(", "om", "*", "OutgoingMessage", ",", "kbState", "string", ",", "oldButtonState", "int", ",", "buttonData", "string", ",", "newButtonState", "int", ",", "newButtonText", "string", ")", "error", ...
// EditInlineStateButton edit the outgoing message's inline button with a state
[ "EditInlineStateButton", "edit", "the", "outgoing", "message", "s", "inline", "button", "with", "a", "state" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L789-L847
train
requilence/integram
context.go
AnswerInlineQueryWithPM
func (c *Context) AnswerInlineQueryWithPM(text string, parameter string) error { bot := c.Bot() _, err := bot.API.AnswerInlineQuery(tg.InlineConfig{IsPersonal: true, InlineQueryID: c.InlineQuery.ID, SwitchPMText: text, SwitchPMParameter: parameter}) n := time.Now() c.inlineQueryAnsweredAt = &n return err }
go
func (c *Context) AnswerInlineQueryWithPM(text string, parameter string) error { bot := c.Bot() _, err := bot.API.AnswerInlineQuery(tg.InlineConfig{IsPersonal: true, InlineQueryID: c.InlineQuery.ID, SwitchPMText: text, SwitchPMParameter: parameter}) n := time.Now() c.inlineQueryAnsweredAt = &n return err }
[ "func", "(", "c", "*", "Context", ")", "AnswerInlineQueryWithPM", "(", "text", "string", ",", "parameter", "string", ")", "error", "{", "bot", ":=", "c", ".", "Bot", "(", ")", "\n", "_", ",", "err", ":=", "bot", ".", "API", ".", "AnswerInlineQuery", ...
// AnswerInlineQueryWithPM answer the inline query that triggered this request with Private Message redirect tip
[ "AnswerInlineQueryWithPM", "answer", "the", "inline", "query", "that", "triggered", "this", "request", "with", "Private", "Message", "redirect", "tip" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L868-L874
train
requilence/integram
context.go
AnswerCallbackQuery
func (c *Context) AnswerCallbackQuery(text string, showAlert bool) error { if c.Callback == nil { return errors.New("Callback to answer is not presented") } if c.Callback.AnsweredAt != nil { return errors.New("Callback already answered") } bot := c.Bot() _, err := bot.API.AnswerCallbackQuery(tg.CallbackCon...
go
func (c *Context) AnswerCallbackQuery(text string, showAlert bool) error { if c.Callback == nil { return errors.New("Callback to answer is not presented") } if c.Callback.AnsweredAt != nil { return errors.New("Callback already answered") } bot := c.Bot() _, err := bot.API.AnswerCallbackQuery(tg.CallbackCon...
[ "func", "(", "c", "*", "Context", ")", "AnswerCallbackQuery", "(", "text", "string", ",", "showAlert", "bool", ")", "error", "{", "if", "c", ".", "Callback", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", ...
// AnswerCallbackQuery answer the inline keyboard callback query that triggered this request with toast or alert
[ "AnswerCallbackQuery", "answer", "the", "inline", "keyboard", "callback", "query", "that", "triggered", "this", "request", "with", "toast", "or", "alert" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L883-L900
train
requilence/integram
context.go
NewMessage
func (c *Context) NewMessage() *OutgoingMessage { bot := c.Bot() msg := &OutgoingMessage{} msg.BotID = bot.ID msg.FromID = bot.ID msg.WebPreview = true if c.Chat.ID != 0 { msg.ChatID = c.Chat.ID } else { msg.ChatID = c.User.ID } msg.ctx = c return msg }
go
func (c *Context) NewMessage() *OutgoingMessage { bot := c.Bot() msg := &OutgoingMessage{} msg.BotID = bot.ID msg.FromID = bot.ID msg.WebPreview = true if c.Chat.ID != 0 { msg.ChatID = c.Chat.ID } else { msg.ChatID = c.User.ID } msg.ctx = c return msg }
[ "func", "(", "c", "*", "Context", ")", "NewMessage", "(", ")", "*", "OutgoingMessage", "{", "bot", ":=", "c", ".", "Bot", "(", ")", "\n", "msg", ":=", "&", "OutgoingMessage", "{", "}", "\n", "msg", ".", "BotID", "=", "bot", ".", "ID", "\n", "msg"...
// NewMessage creates the message targeted to the current chat
[ "NewMessage", "creates", "the", "message", "targeted", "to", "the", "current", "chat" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L903-L916
train
requilence/integram
context.go
SendAction
func (c *Context) SendAction(s string) error { _, err := c.Bot().API.Send(tg.NewChatAction(c.Chat.ID, s)) return err }
go
func (c *Context) SendAction(s string) error { _, err := c.Bot().API.Send(tg.NewChatAction(c.Chat.ID, s)) return err }
[ "func", "(", "c", "*", "Context", ")", "SendAction", "(", "s", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "Bot", "(", ")", ".", "API", ".", "Send", "(", "tg", ".", "NewChatAction", "(", "c", ".", "Chat", ".", "ID", ",", "s"...
// SendAction send the one of "typing", "upload_photo", "record_video", "upload_video", "record_audio", "upload_audio", "upload_document", "find_location"
[ "SendAction", "send", "the", "one", "of", "typing", "upload_photo", "record_video", "upload_video", "record_audio", "upload_audio", "upload_document", "find_location" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L919-L922
train
requilence/integram
context.go
DownloadURL
func (c *Context) DownloadURL(url string) (filePath string, err error) { ext := filepath.Ext(url) out, err := ioutil.TempFile("", fmt.Sprintf("%d_%d", c.Bot().ID, c.Chat.ID)) if err != nil { return "", err } out.Close() os.Rename(out.Name(), out.Name()+ext) out, err = os.OpenFile(out.Name()+ext, os.O_RDWR,...
go
func (c *Context) DownloadURL(url string) (filePath string, err error) { ext := filepath.Ext(url) out, err := ioutil.TempFile("", fmt.Sprintf("%d_%d", c.Bot().ID, c.Chat.ID)) if err != nil { return "", err } out.Close() os.Rename(out.Name(), out.Name()+ext) out, err = os.OpenFile(out.Name()+ext, os.O_RDWR,...
[ "func", "(", "c", "*", "Context", ")", "DownloadURL", "(", "url", "string", ")", "(", "filePath", "string", ",", "err", "error", ")", "{", "ext", ":=", "filepath", ".", "Ext", "(", "url", ")", "\n", "out", ",", "err", ":=", "ioutil", ".", "TempFile...
// DownloadURL downloads the remote URL and returns the local file path
[ "DownloadURL", "downloads", "the", "remote", "URL", "and", "returns", "the", "local", "file", "path" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L925-L958
train
requilence/integram
context.go
RAW
func (wc *WebhookContext) RAW() (*[]byte, error) { var err error if wc.body == nil { wc.firstParse = true wc.body, err = ioutil.ReadAll(wc.gin.Request.Body) if err != nil { return nil, err } } return &wc.body, nil }
go
func (wc *WebhookContext) RAW() (*[]byte, error) { var err error if wc.body == nil { wc.firstParse = true wc.body, err = ioutil.ReadAll(wc.gin.Request.Body) if err != nil { return nil, err } } return &wc.body, nil }
[ "func", "(", "wc", "*", "WebhookContext", ")", "RAW", "(", ")", "(", "*", "[", "]", "byte", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "wc", ".", "body", "==", "nil", "{", "wc", ".", "firstParse", "=", "true", "\n", "wc", ".", ...
// RAW returns request's body
[ "RAW", "returns", "request", "s", "body" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L961-L971
train
requilence/integram
context.go
JSON
func (wc *WebhookContext) JSON(out interface{}) error { var err error if wc.body == nil { wc.firstParse = true wc.body, err = ioutil.ReadAll(wc.gin.Request.Body) if err != nil { return err } } err = json.Unmarshal(wc.body, out) if err != nil && strings.HasPrefix(string(wc.body), "payload=") { s := s...
go
func (wc *WebhookContext) JSON(out interface{}) error { var err error if wc.body == nil { wc.firstParse = true wc.body, err = ioutil.ReadAll(wc.gin.Request.Body) if err != nil { return err } } err = json.Unmarshal(wc.body, out) if err != nil && strings.HasPrefix(string(wc.body), "payload=") { s := s...
[ "func", "(", "wc", "*", "WebhookContext", ")", "JSON", "(", "out", "interface", "{", "}", ")", "error", "{", "var", "err", "error", "\n", "if", "wc", ".", "body", "==", "nil", "{", "wc", ".", "firstParse", "=", "true", "\n", "wc", ".", "body", ",...
// JSON decodes the JSON in the request's body to the out interface
[ "JSON", "decodes", "the", "JSON", "in", "the", "request", "s", "body", "to", "the", "out", "interface" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L974-L996
train
requilence/integram
context.go
Form
func (wc *WebhookContext) Form() uurl.Values { //todo: bug, RAW() unavailable after ParseForm() wc.gin.Request.ParseForm() return wc.gin.Request.PostForm }
go
func (wc *WebhookContext) Form() uurl.Values { //todo: bug, RAW() unavailable after ParseForm() wc.gin.Request.ParseForm() return wc.gin.Request.PostForm }
[ "func", "(", "wc", "*", "WebhookContext", ")", "Form", "(", ")", "uurl", ".", "Values", "{", "//todo: bug, RAW() unavailable after ParseForm()", "wc", ".", "gin", ".", "Request", ".", "ParseForm", "(", ")", "\n", "return", "wc", ".", "gin", ".", "Request", ...
// Form decodes the POST form in the request's body to the out interface
[ "Form", "decodes", "the", "POST", "form", "in", "the", "request", "s", "body", "to", "the", "out", "interface" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L999-L1003
train
requilence/integram
tgupdates.go
IsEventBotAddedToGroup
func (m *IncomingMessage) IsEventBotAddedToGroup() bool { if (len(m.NewChatMembers) > 0 && m.NewChatMembers[0].ID == m.BotID) || m.GroupChatCreated || m.SuperGroupChatCreated { return true } return false }
go
func (m *IncomingMessage) IsEventBotAddedToGroup() bool { if (len(m.NewChatMembers) > 0 && m.NewChatMembers[0].ID == m.BotID) || m.GroupChatCreated || m.SuperGroupChatCreated { return true } return false }
[ "func", "(", "m", "*", "IncomingMessage", ")", "IsEventBotAddedToGroup", "(", ")", "bool", "{", "if", "(", "len", "(", "m", ".", "NewChatMembers", ")", ">", "0", "&&", "m", ".", "NewChatMembers", "[", "0", "]", ".", "ID", "==", "m", ".", "BotID", "...
// IsEventBotAddedToGroup returns true if user created a new group with bot as member or add the bot to existing group
[ "IsEventBotAddedToGroup", "returns", "true", "if", "user", "created", "a", "new", "group", "with", "bot", "as", "member", "or", "add", "the", "bot", "to", "existing", "group" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/tgupdates.go#L768-L773
train
requilence/integram
tgupdates.go
GetCommand
func (m *IncomingMessage) GetCommand() (string, string) { text := m.Text if !strings.HasPrefix(text, "/") { return "", text } r, _ := regexp.Compile("^/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?.?(.*)?$") match := r.FindStringSubmatch(text) if len(match) == 3 { return match[1], match[2] } else if len(match) == 2 { ...
go
func (m *IncomingMessage) GetCommand() (string, string) { text := m.Text if !strings.HasPrefix(text, "/") { return "", text } r, _ := regexp.Compile("^/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?.?(.*)?$") match := r.FindStringSubmatch(text) if len(match) == 3 { return match[1], match[2] } else if len(match) == 2 { ...
[ "func", "(", "m", "*", "IncomingMessage", ")", "GetCommand", "(", ")", "(", "string", ",", "string", ")", "{", "text", ":=", "m", ".", "Text", "\n\n", "if", "!", "strings", ".", "HasPrefix", "(", "text", ",", "\"", "\"", ")", "{", "return", "\"", ...
// GetCommand parses received message text for bot command. Returns the command and after command text if presented
[ "GetCommand", "parses", "received", "message", "text", "for", "bot", "command", ".", "Returns", "the", "command", "and", "after", "command", "text", "if", "presented" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/tgupdates.go#L776-L791
train
requilence/integram
bots.go
Find
func (keyboard *InlineKeyboard) Find(buttonData string) (i, j int, but *InlineButton) { for i, buttonsRow := range keyboard.Buttons { for j, button := range buttonsRow { if button.Data == buttonData { return i, j, &button } } } return -1, -1, nil }
go
func (keyboard *InlineKeyboard) Find(buttonData string) (i, j int, but *InlineButton) { for i, buttonsRow := range keyboard.Buttons { for j, button := range buttonsRow { if button.Data == buttonData { return i, j, &button } } } return -1, -1, nil }
[ "func", "(", "keyboard", "*", "InlineKeyboard", ")", "Find", "(", "buttonData", "string", ")", "(", "i", ",", "j", "int", ",", "but", "*", "InlineButton", ")", "{", "for", "i", ",", "buttonsRow", ":=", "range", "keyboard", ".", "Buttons", "{", "for", ...
// Find the InlineButton in Keyboard by the Data
[ "Find", "the", "InlineButton", "in", "Keyboard", "by", "the", "Data" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L305-L314
train
requilence/integram
bots.go
EditText
func (keyboard *InlineKeyboard) EditText(buttonData string, newText string) { for i, buttonsRow := range keyboard.Buttons { for j, button := range buttonsRow { if button.Data == buttonData { keyboard.Buttons[i][j].Text = newText return } } } }
go
func (keyboard *InlineKeyboard) EditText(buttonData string, newText string) { for i, buttonsRow := range keyboard.Buttons { for j, button := range buttonsRow { if button.Data == buttonData { keyboard.Buttons[i][j].Text = newText return } } } }
[ "func", "(", "keyboard", "*", "InlineKeyboard", ")", "EditText", "(", "buttonData", "string", ",", "newText", "string", ")", "{", "for", "i", ",", "buttonsRow", ":=", "range", "keyboard", ".", "Buttons", "{", "for", "j", ",", "button", ":=", "range", "bu...
// EditText find the InlineButton in Keyboard by the Data and change the text of that button
[ "EditText", "find", "the", "InlineButton", "in", "Keyboard", "by", "the", "Data", "and", "change", "the", "text", "of", "that", "button" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L317-L326
train
requilence/integram
bots.go
AddPMSwitchButton
func (keyboard *InlineKeyboard) AddPMSwitchButton(b *Bot, text string, param string) { if len(keyboard.Buttons) > 0 && len(keyboard.Buttons[0]) > 0 && keyboard.Buttons[0][0].Text == text { return } keyboard.PrependRows(InlineButtons{InlineButton{Text: text, URL: b.PMURL(param)}}) }
go
func (keyboard *InlineKeyboard) AddPMSwitchButton(b *Bot, text string, param string) { if len(keyboard.Buttons) > 0 && len(keyboard.Buttons[0]) > 0 && keyboard.Buttons[0][0].Text == text { return } keyboard.PrependRows(InlineButtons{InlineButton{Text: text, URL: b.PMURL(param)}}) }
[ "func", "(", "keyboard", "*", "InlineKeyboard", ")", "AddPMSwitchButton", "(", "b", "*", "Bot", ",", "text", "string", ",", "param", "string", ")", "{", "if", "len", "(", "keyboard", ".", "Buttons", ")", ">", "0", "&&", "len", "(", "keyboard", ".", "...
// AddPMSwitchButton add the button to switch to PM as a first row in the InlineKeyboard
[ "AddPMSwitchButton", "add", "the", "button", "to", "switch", "to", "PM", "as", "a", "first", "row", "in", "the", "InlineKeyboard" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L329-L334
train