Skip to content

ellieasager/hackernewsJwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hackernews

A project to learn integration of go with gqlgen

A Hackernews clone with Go, GraphQL and JWT.

The API should be able to handle registration, authentication, submitting links and getting list of links.

Instructions

  1. In MySQL db
CREATE DATABASE hackernews;
  1. Cli
git clone https://github.com/ellieasager/hackernewsJwt
cd hackernewsJwt
printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
go mod tidy
  1. In code: In the file internal/pkg/db/mysql/mysql.go set username and password for the db connection in method InitDB().

  2. 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
  1. Cli: go run server.go

  2. In your browser go to http://localhost:8080/

  • Create a user:
mutation {
  createUser(input: {username: "new user", password: "password"}){
    id,
    name
  }
}
  • List existing users:
query {
  users {
    id
    name
  }
}
  1. If you need to re-generate files, run
go run github.com/99designs/gqlgen generate

About

Go + GraphQL + Auth via JWT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages