A basic twitter app to search tweets and to display user's home feed.
See demo here.
dep
- Go dependencies management tool https://golang.github.io/dephero
- Html templating engine for Go https://github.com/shiyanhui/hero- Install
hero
cligo get -u github.com/shiyanhui/hero/hero
- Install
Instructions are based on considering the repo is cloned into a Go workspace
- Rename
dev.env
as.env
, set exports for environment variables for local development, including Twitter app credentials:
TWTRGO_ENV=default
PORT=8080
TWITTER_CONSUMER_KEY=<consumer-key>
TWITTER_CONSUMER_SECRET=<consumer-secret>
TWITTER_ACCESS_TOKEN=<access-token>
TWITTER_ACCESS_TOKEN_SECRET=<access-token-secret>
Otherwise export environment variables directly in terminal, whichever is preferable
- Install
hero
cli as mentioned in Dependencies. Html templates are compiled into directoryhttp/templates
. If need to recompile templates fromhttp/templates/src
run:
$ make template
Default package name will be
github.com/jinmatt/twtrgo/http/template
. The render functions can be found under http/template/src inside .html files(home/search/error)
- Build app:
$ make build
- Run tests:
$ make test
- Run app:
$ make
App starts on default port set in .env file (PORT=8080 ; https://localhost:8080)
The app package layout is based on an approach to scale(Ref. here).
twtrgo
- The main package holds Tweets type and TweetService interface services should implement based on the requirementstwitter
- implements twtrgo.TweetService interface with Twitter API client. Can be swapped out with other implementations or to use a cache/db servicehttp/handler
- Handles http routesservices
- Handles global connection/client objects like API/DB/cache objects, so they are only initialized once and destroyed onceconfig
- Handles runtime configscmd/twtrgo
- App binary package, inits configs, services and starts http servermock
- A mock package for tests, implements twtrgo.TweetServicetest
- Test package, tests only http routes(behavioral tests)