Skip to content

Commit

Permalink
Merge pull request #8 from biter777/master
Browse files Browse the repository at this point in the history
Load a default emoji data, if file emoji.json is missing
  • Loading branch information
tmdvs authored Feb 11, 2020
2 parents 47a2e17 + ee721e7 commit 89e1e92
Show file tree
Hide file tree
Showing 2 changed files with 15,886 additions and 6 deletions.
17 changes: 11 additions & 6 deletions emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ type Emoji struct {
Descriptor string `json:"descriptor"`
}

// Emojis - Map of Emoji Runes as Hex keys to their description
var Emojis map[string]Emoji

// Unmarshal the emoji JSON into the Emojis map
func init() {
// Work out where we are in relation to the caller
Expand All @@ -32,17 +29,25 @@ func init() {

// Open the Emoji definition JSON and Unmarshal into map
jsonFile, err := os.Open(path.Dir(filename) + "/data/emoji.json")
defer jsonFile.Close()
if err != nil {
if jsonFile != nil {
defer jsonFile.Close()
}
if err != nil && len(Emojis) < 1 {
fmt.Println(err)
}

byteValue, e := ioutil.ReadAll(jsonFile)
if e != nil {
if len(Emojis) > 0 { // Use build-in emojis data (from emojidata.go)
return
}
panic(e)
}

json.Unmarshal(byteValue, &Emojis)
err = json.Unmarshal(byteValue, &Emojis)
if err != nil {
panic(e)
}
}

// LookupEmoji - Lookup a single emoji definition
Expand Down
Loading

0 comments on commit 89e1e92

Please sign in to comment.