-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pushstream: article content (long-)polling.
- Loading branch information
1 parent
0d18a17
commit f7a3e3f
Showing
7 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package page | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type ArticlePollResp struct { | ||
ContentHtml string `json:"contentHtml"` | ||
PollUrl string `json:"pollUrl"` | ||
Success bool `json:"success"` | ||
} | ||
|
||
func WriteAjaxResp(w http.ResponseWriter, obj interface{}) error { | ||
w.Header().Set("Content-Type", "application/json") | ||
return json.NewEncoder(w).Encode(obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pushstream | ||
|
||
import ( | ||
"crypto/sha1" | ||
"fmt" | ||
) | ||
|
||
type PushNotification struct { | ||
Brdname string `json:"brdname"` | ||
Filename string `json:"filename"` | ||
Size int64 `json:"size"` | ||
Signature string `json:"sig"` | ||
} | ||
|
||
func (p *PushNotification) Sign(secret string) { | ||
p.Signature = p.calcSig(secret) | ||
} | ||
|
||
func (p *PushNotification) CheckSignature(secret string) bool { | ||
return p.Signature == p.calcSig(secret) | ||
} | ||
|
||
func (p *PushNotification) calcSig(secret string) string { | ||
return sha1hex(fmt.Sprintf("%v/%v/%v/%v", p.Brdname, p.Filename, p.Size, secret)) | ||
} | ||
|
||
func GetPushChannel(p *PushNotification, secret string) string { | ||
return sha1hex(fmt.Sprintf("%v/%v/%v", p.Brdname, p.Filename, secret)) | ||
} | ||
|
||
func sha1hex(s string) string { | ||
return fmt.Sprintf("%x", sha1.Sum([]byte(s))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters