Skip to content

Instantly share code, notes, and snippets.

// https://play.golang.org/p/2LBJbIBVw37
package main
import (
"fmt"
)
type Foo struct {
name string
}
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func main() {
package users
import (
"encoding/json"
)
// UserProfile contains all the information details of a given user
type UserProfile struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
@suzuki-shunsuke
suzuki-shunsuke / decode_hook.go
Last active March 29, 2018 05:16
sample code of mapstructure's DecodeHook
package main
import (
"fmt"
"log"
"reflect"
"github.com/mitchellh/mapstructure"
"github.com/suzuki-shunsuke/go-set"
)
{
"permissions" : {
"outputs" : [ "create", "edit", "terminate", "read" ],
"sources" : [ "read" ],
"indexranges" : [ "read", "rebuild" ],
"deflector" : [ "read", "cycle" ],
"loggers" : [ "readsubsystem", "edit", "editsubsystem", "read" ],
"inputs" : [ "terminate", "read", "create", "changestate", "edit" ],
"lbstatus" : [ "change" ],
"roles" : [ "edit", "create", "read", "delete" ],
@suzuki-shunsuke
suzuki-shunsuke / playbook.yml
Created January 5, 2018 12:58
ansibleのshell(command)モジュールで標準出力によってchangedを判定する方法
---
- hosts: localhost
tasks:
- shell: "echo '{\"changed\": true}'"
register: result
changed_when: (result.stdout|from_json)["changed"]
- shell: "echo '{\"changed\": false}'"
register: result
changed_when: (result.stdout|from_json)["changed"]
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/ghodss/yaml"
)
@suzuki-shunsuke
suzuki-shunsuke / error.go
Created September 15, 2017 14:28
runtimeエラーを処理する汎用的なコード。
package models
type RuntimeError interface {
Param() interface{} // runtimeエラーが起こった祭のpanic()の引数を取得
Error() string
}
type runtimeErrorImpl struct {
data struct {
param interface{}
@suzuki-shunsuke
suzuki-shunsuke / upgrade-node
Last active August 14, 2017 02:24
nodebrew の nodeのバージョンアップするスクリプト
#!/usr/bin/env zsh
set -e
NODE_VERSION=$1
nodebrew install-binary $NODE_VERSION
nodebrew use $NODE_VERSION
PACKAGES=(
@suzuki-shunsuke
suzuki-shunsuke / upgrade-node
Created August 2, 2017 03:57
nodebrew の nodeのバージョンアップするスクリプト
#!/usr/bin/env zsh
set -e
NODE_VERSION=$1
nodebrew install-binary $NODE_VERSION
nodebrew use $NODE_VERSION
PACKAGES=(