-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add testAndSet Command #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,35 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) { | |
|
||
} | ||
|
||
func TestAndSetHttpHandler(w http.ResponseWriter, req *http.Request) { | ||
key := req.URL.Path[len("/v1/testAndSet/"):] | ||
|
||
debug("[recv] POST http://%v/v1/testAndSet/%s", server.Name(), key) | ||
|
||
command := &TestAndSetCommand{} | ||
command.Key = key | ||
|
||
command.PrevValue = req.FormValue("prevValue") | ||
command.Value = req.FormValue("value") | ||
strDuration := req.FormValue("ttl") | ||
|
||
if strDuration != "" { | ||
duration, err := strconv.Atoi(strDuration) | ||
|
||
if err != nil { | ||
warn("raftd: Bad duration: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/raftd/etcd/g |
||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
command.ExpireTime = time.Now().Add(time.Second * (time.Duration)(duration)) | ||
} else { | ||
command.ExpireTime = time.Unix(0, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't an uninitialized time start out at 0 anyways? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://play.golang.org/p/WsKT0YYum_ |
||
} | ||
|
||
excute(command, &w, req) | ||
|
||
} | ||
|
||
func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) { | ||
key := req.URL.Path[len("/v1/keys/"):] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, this bit of code seems to be copied for every handler. We may want to use something like Gorilla's logging handler:
http://www.gorillatoolkit.org/pkg/handlers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using mux before, but found some problem it cannot deal with.
I will clean up the codes after a while.
We need both http and https support. I am going to abstract that layer out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the problem with the Mux? We are using it elsewhere so it would be good to know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fdd6873
Since our keys contain '/'. like we need to handle http://127.0.0.1:4001/keys/foo/foo/foo with /key
I checked the mux at that time, and think do it by myself is more easy.