MCPcopy Index your code
hub / github.com/koding/kite / Update

Method Update

kontrol/etcd.go:140–189  ·  view source on GitHub ↗
(k *protocol.Kite, v *kontrolprotocol.RegisterValue)

Source from the content-addressed store, hash-verified

138}
139
140func (e *Etcd) Update(k *protocol.Kite, v *kontrolprotocol.RegisterValue) error {
141 etcdKey := KitesPrefix + k.String()
142 etcdIDKey := KitesPrefix + "/" + k.ID
143
144 p, err := json.Marshal(v)
145 if err != nil {
146 return err
147 }
148
149 value := string(p)
150
151 // update the kite key.
152 // Example "/koding/production/os/0.0.1/sj/kontainer1.sj.koding.com/1234asdf..."
153 _, err = e.client.Set(context.TODO(),
154 etcdKey,
155 value,
156 &etcd.SetOptions{
157 TTL: KeyTTL,
158 PrevExist: etcd.PrevExist,
159 },
160 )
161 if err != nil {
162 // TODO(rjeczalik): Add only if err == KeyNotFound?
163 return e.Add(k, v)
164 }
165
166 // Also update the the kite.Key Id for easy lookup
167 _, err = e.client.Set(context.TODO(),
168 etcdIDKey,
169 value,
170 &etcd.SetOptions{
171 TTL: KeyTTL,
172 PrevExist: etcd.PrevExist,
173 },
174 )
175 if err != nil {
176 return err
177 }
178
179 // Set the TTL for the username. Otherwise, empty dirs remain in etcd.
180 _, err = e.client.Set(context.TODO(),
181 KitesPrefix+"/"+k.Username,
182 "",
183 &etcd.SetOptions{
184 TTL: KeyTTL,
185 PrevExist: etcd.PrevExist,
186 },
187 )
188 return err
189}
190
191func (e *Etcd) Get(query *protocol.KontrolQuery) (Kites, error) {
192 // We will make a get request to etcd store with this key. So get a "etcd"

Callers

nothing calls this directly

Calls 3

AddMethod · 0.95
StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected