This project has both react-native and golang applications in separate branches. All you need to do is follow these instructions to run them without a hassle. Although, there is no routes setup on the frontend for OAuth with twitch, there is OAuth setup in the golang application, and you check that while hitting the route. I will also specify what routes I created and how do you have to run this project. But first ....
This project uses dotenv
configuration for accessing environment variables,
you must create variables.env
file and this file must have these properties
TWITCH_CLIENT_ID : XXXXXXXXXXXXXXXXXXXXXXXXXX
TWITCH_CLIENT_SECRET : XXXXXXXXXXXXXXXXXXXXXX
MYSQL_DATA_URL : XXXXXXXXXXXXXXXXXXXXXX
REDIRECT_URI : XXXXXXXXXXXXXXXXXXXXXX
PRIVATE_IP : XXXXXXXXXXXXXXXXXXXXXX
MODE : XXXXXXXXXXXXXXXXXXXXXX // AUTH or anything else!!
after you set this up in the root directory, you can run
go run main.go
As the project does not have the auth routes for frontend, you need to specify the mode of the golang application and run it on either Postman or your browser.
By root directory, I mean the directory where main.go is present, which is
$GOPATH/src/github.com/krishnadubagunta/golang/gawkbox-assignment/
in the terminal, run this line to get the project in your go/src/github
go get github.com/krishnadubagunta/golang/gawkbox-assignment
you can go to this repository and run the main.go provided, you have met the pre-requisites mentioned above. i.e., you should create variables.env
file in the project directory before running it.
You can now run this command, and make sure you're in the root directory of this project. Which is, /go/src/github.com/krishnadubagunta/golang/gawkbox-assignment
Please follow the instructions on MySQL to install MySQL on your local machine, and make sure that you have twitch database in it before running the server
go run main.go
you should see this as output,
2018/03/18 12:35:50 There initializes the oauth
2018/03/18 12:35:50 DB : &{<nil> <nil> 0 0xc42019a780 false 0 {0xc420147ef0} <nil> map[] 0xc4201b8000 0x1626600 0xc4201a6a60 false}
false
Server Booted...
if this is the first time you're running this, you will see true
before Server Booted...
as you don't have Users
table in your twitch database, this program creates it for you.
This is present in the react-native branch of this repository.
This project uses CRNA CLI to create the application, and react-native-elements for the UI.
All you need to do here is , again, setup the environment variables, which in this case, just one.
HOST = xxxxxxxxx
this variable is given because, if MODE=AUTH
in the Golang API, then there is no way we can use localhost
for android and iOS, instead we have to use something called localtunnel to expose our api server to public. now this id that localtunnel gives, can be used in HOST=
, and everything runs perfectly.
if MODE=notAuth
then we can directly use our IP address as HOST=10.0.0.82:8080
with the port number, which is 8080.
if android gives you any problem, which it gives, you have to reverse-map the port numbers of the device to the machine's port, like
adb reverse tcp:8080 tcp:8080
User screen after selecting a stream from the list:
Searching users from the database:
Live search from SQL database cannot happen until you signin or signup using OAuth for this application. i.e., for this feature to return any users, you need to use MODE=AUTH
atleast once in the Golang API.
/api/auth
/api/streams
/api/user/{id}