Example #1
0
// Set sets the value for a given key.
func (h *kvHandler) Set(ctx thrift.Context, key, value string) error {
	if err := isValidKey(key); err != nil {
		return err
	}

	h.mut.Lock()
	defer h.mut.Unlock()

	h.vals[key] = value
	// Example of how to use response headers. Normally, these values should be passed via result structs.
	ctx.SetResponseHeaders(map[string]string{"count": fmt.Sprint(len(h.vals))})
	return nil
}
Example #2
0
func isAdmin(ctx thrift.Context) bool {
	return ctx.Headers()["user"] == "admin"
}