A project to learn integration of go with gqlgen
A Hackernews clone with Go and gqlgen.
The API should be able to handle registration, authentication, submitting links and getting list of links.
- In MySQL db
CREATE DATABASE hackernews;
- Cli
git clone https://github.com/ellieasager/hackernews
cd hackernews
printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
go mod tidy
-
In code: In the file
internal/pkg/db/mysql/mysql.go
set username and password for the db connection in methodInitDB()
. -
Cli: make sure to use your username and password when running the command below
migrate -database mysql://root:dbpassword@/hackernews -path internal/pkg/db/migrations/mysql up
-
Cli:
go run server.go
-
In your browser go to http://localhost:8080/
- Try creating a user:
mutation {
createUser(input: {username: "new user", password: "password"}){
id,
name
}
}
- List existing users:
query {
users {
id
name
}
}
- If you need to re-generate files, run
go run github.com/99designs/gqlgen generate