-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a route with a list of all cached requests (#22)
- Loading branch information
Showing
10 changed files
with
213 additions
and
7 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
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
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,57 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
sf "github.com/sa-/slicefunk" | ||
) | ||
|
||
func getParseCacheKey(cacheType string) func(string) map[string]interface{} { | ||
return func(key string) map[string]interface{} { | ||
parts := strings.Split(key, ",") | ||
|
||
switch cacheType { | ||
case "/adventurer": | ||
return map[string]interface{}{ | ||
"region": parts[0], | ||
"profileTarget": parts[1], | ||
} | ||
case "/adventurer/search": | ||
page, _ := strconv.Atoi(parts[3]) | ||
|
||
return map[string]interface{}{ | ||
"region": parts[0], | ||
"query": parts[1], | ||
"searhType": parts[2], | ||
"page": page, | ||
} | ||
case "/guild": | ||
return map[string]interface{}{ | ||
"region": parts[0], | ||
"guildName": parts[1], | ||
} | ||
case "/guild/search": | ||
page, _ := strconv.Atoi(parts[2]) | ||
|
||
return map[string]interface{}{ | ||
"region": parts[0], | ||
"query": parts[1], | ||
"page": page, | ||
} | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
func GetCache(w http.ResponseWriter, r *http.Request) { | ||
json.NewEncoder(w).Encode(map[string]interface{}{ | ||
"/adventurer": sf.Map(profilesCache.GetKeys(), getParseCacheKey("/adventurer")), | ||
"/adventurer/search": sf.Map(profileSearchCache.GetKeys(), getParseCacheKey("/adventurer/search")), | ||
"/guild": sf.Map(guildProfilesCache.GetKeys(), getParseCacheKey("/guild")), | ||
"/guild/search": sf.Map(guildSearchCache.GetKeys(), getParseCacheKey("/guild/search")), | ||
}) | ||
} |
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