-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read quotes, quote struct and get random quote
- Loading branch information
1 parent
1ff87d9
commit fcf83ab
Showing
6 changed files
with
260 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
[ | ||
{ | ||
"quote": "A persistência é o caminho do êxito.", | ||
"author": "Charles Chaplin" | ||
}, | ||
{ | ||
"quote": "As pessoas costumam dizer que a motivação não dura sempre. Bem, nem o efeito do banho, por isso recomenda-se diariamente.", | ||
"author": "Zig Ziglar" | ||
}, | ||
{ | ||
"quote": "Motivação é a arte de fazer as pessoas fazerem o que você quer que elas façam porque elas o querem fazer.", | ||
"author": "Dwight Eisenhower" | ||
}, | ||
{ | ||
"quote": "Toda ação humana, quer se torne positiva ou negativa, precisa depender de motivação.", | ||
"author": "Dalai Lama" | ||
}, | ||
{ | ||
"quote": "No meio da dificuldade encontra-se a oportunidade.", | ||
"author": "Desconhecido" | ||
}, | ||
{ | ||
"quote": "Lute. Acredite. Conquiste. Perca. Deseje. Espere. Alcance. Invada. Caia. Seja tudo o quiser ser, mas acima de tudo, seja você sempre.", | ||
"author": "Tumblr" | ||
}, | ||
{ | ||
"quote": "Eu faço da dificuldade a minha motivação. A volta por cima vem na continuação.", | ||
"author": "Charlie Brown Jr" | ||
}, | ||
{ | ||
"quote": "A verdadeira motivação vem de realização, desenvolvimento pessoal, satisfação no trabalho e reconhecimento.", | ||
"author": "Frederick Herzberg" | ||
}, | ||
{ | ||
"quote": "Pedras no caminho? Eu guardo todas. Um dia vou construir um castelo.", | ||
"author": "Nemo Nox" | ||
}, | ||
{ | ||
"quote": "É parte da cura o desejo de ser curado.", | ||
"author": "Sêneca" | ||
}, | ||
{ | ||
"quote": "Tudo o que um sonho precisa para ser realizado é alguém que acredite que ele possa ser realizado.", | ||
"author": "Roberto Shinyashiki" | ||
}, | ||
{ | ||
"quote": "O que me preocupa não é o grito dos maus. É o silêncio dos bons.", | ||
"author": "Martin Luther King" | ||
}, | ||
{ | ||
"quote": "Imagine uma nova história para sua vida e acredite nela.", | ||
"author": "Paulo Coelho" | ||
}, | ||
{ | ||
"quote": "O insucesso é apenas uma oportunidade para recomeçar com mais inteligência.", | ||
"author": "Henry Ford" | ||
}, | ||
{ | ||
"quote": "Quando você quer alguma coisa, todo o universo conspira para que você realize o seu desejo.", | ||
"author": "Paulo Coelho" | ||
}, | ||
{ | ||
"quote": "Você precisa fazer aquilo que pensa que não é capaz de fazer.", | ||
"author": "Eleanor Roosevelt" | ||
}, | ||
{ | ||
"quote": "O sucesso é ir de fracasso em fracasso sem perder entusiasmo.", | ||
"author": "Winston Churchill" | ||
}, | ||
{ | ||
"quote": "Só se pode alcançar um grande êxito quando nos mantemos fiéis a nós mesmos.", | ||
"author": "Friedrich Nietzsche" | ||
}, | ||
{ | ||
"quote": "Lute com determinação, abrace a vida com paixão, perca com classe e vença com ousadia, porque o mundo pertence a quem se atreve e a vida é muito para ser insignificante.", | ||
"author": "Augusto Branco" | ||
}, | ||
{ | ||
"quote": "Nossa maior fraqueza está em desistir. O caminho mais certo de vencer é tentar mais uma vez.", | ||
"author": "Thomas Edison" | ||
} | ||
] |
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
module motivar | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/markbates/pkger v0.17.1 | ||
github.com/mitchellh/go-homedir v1.1.0 | ||
github.com/smartystreets/goconvey v1.6.4 // indirect | ||
gopkg.in/ini.v1 v1.61.0 | ||
) |
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,40 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI= | ||
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= | ||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= | ||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= | ||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= | ||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= | ||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno= | ||
github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= | ||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= | ||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= | ||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= | ||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/ini.v1 v1.61.0 h1:LBCdW4FmFYL4s/vDZD1RQYX7oAR6IjujCYgMdbHBR10= | ||
gopkg.in/ini.v1 v1.61.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= | ||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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 |
---|---|---|
@@ -1,7 +1,135 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"os" | ||
"path" | ||
"time" | ||
|
||
"github.com/markbates/pkger" | ||
"github.com/mitchellh/go-homedir" | ||
|
||
"gopkg.in/ini.v1" | ||
) | ||
|
||
var ( | ||
homeDir string | ||
|
||
cfgDir string | ||
cfgFile string | ||
cfgDataDir string | ||
|
||
quotesBR []phrase | ||
quotesUS []phrase | ||
) | ||
|
||
type phrase struct { | ||
Quote string `json:"quote"` | ||
Author string `json:"author"` | ||
} | ||
|
||
func init() { | ||
homeDir, err := homedir.Dir() | ||
check(err) | ||
|
||
cfgDir = path.Join(homeDir, ".motivar") | ||
cfgFile = path.Join(cfgDir, "motivar.ini") | ||
cfgDataDir = path.Join(cfgDir, "data") | ||
|
||
err = setup() | ||
check(err) | ||
|
||
err = readPhrases("/data/br/") | ||
check(err) | ||
} | ||
|
||
func main() { | ||
fmt.Println("Firssst") | ||
rand.Seed(time.Now().UnixNano()) | ||
v := rand.Intn(len(quotesBR)-1) + 1 | ||
|
||
q := quotesBR[v] | ||
fmt.Printf("%+v %+v\n", q.Quote, q.Author) | ||
} | ||
|
||
func check(e error) { | ||
if e != nil { | ||
fmt.Printf("error: %+v", e) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func setup() error { | ||
// check and create conf dir | ||
if _, err := os.Stat(cfgDir); os.IsNotExist(err) { | ||
err := os.Mkdir(cfgDir, 0764) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// check and create conf file | ||
if _, err := os.Stat(cfgFile); os.IsNotExist(err) { | ||
_, err := os.Create(cfgFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = makeCfg() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// create data dir | ||
if _, err := os.Stat(cfgDataDir); os.IsNotExist(err) { | ||
err := os.Mkdir(cfgDataDir, 0764) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func makeCfg() error { | ||
cfg, err := ini.Load(cfgFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg.Section("").Key("languages").SetValue("br,us") | ||
err = cfg.SaveTo(cfgFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func readPhrases(path string) error { | ||
pkger.Walk(path, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !info.IsDir() { | ||
f, err := pkger.Open(path) | ||
defer f.Close() | ||
|
||
content, err := ioutil.ReadAll(f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = json.Unmarshal(content, "esBR) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
return nil | ||
} |