Skip to content

Instantly share code, notes, and snippets.

@sumitasok
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumitasok/488c5017f5b62cdda53d to your computer and use it in GitHub Desktop.
Save sumitasok/488c5017f5b62cdda53d to your computer and use it in GitHub Desktop.
A Display of interface and Functional Programming playing hand in hand with OOP - with Golang
package reqresp
type ReqResp interface {
HashableString() string
IgnoreList() map[string]string
}
type Response struct {
Type Type
Details DataTypes
}
func (r *Response) IgnoreList() map[string]string{
return map[string]string{{"key1": "val1"}, "key2": "val2"}
}
func (r *Response) HashableString() {
dict := Actions.Dict(r)
return fmt.Sprintf("%s|%s", dict["amount"], dict["salt"])
}
type Request struct {
Type Type
Details DataTypes
}
func (r *Request) HashableString() {
dict := Actions.Dict(r)
return fmt.Sprintf("%s|%s", dict["key"], dict["salt"])
}
func (r *Request) IgnoreList() map[string]string{
return map[string]string{{"keyo": "valo"}, "keyu": "valu"}
}
// (FP)
type Actions struct {
}
func (a Actions) JSON(req ReqResp []byte{
safe_dict = remove(req.IgnoreList(), dict)
return JSON.marshal(safe_dict)
}
func (a Actions) Dict(req ReqResp) map[string]string {
var dict map[string]string
for i, detail := req.Details {
dict = merge(dict, detail.Dict())
}
return dict
}
// ||| level:(OOP) interface and struct
type DataTypes interface {
Validate()
Dict() map[string]string
}
type UserDetails struct {
Name string
}
func (ud *UserDetails) Validate() {
}
func (ud *UserDetails) Dict() map[string]string {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment