A Contact Manager App built in Go Programming Language. This app implemented the REST API and the GraphQL. One can register and login, and then create, update, delete contacts, and also get a list of contacts.
This project is implemented and tested using go version go1.12 linux/amd64
To install the dependencies list below, type go get <package name>
golang.org/x/crypto/bcrypt
github.com/gorilla/mux
github.com/99designs/gqlgen
github.com/mattn/go-sqlite3
github.com/dgrijalva/jwt-go
github.com/google/uuid
github.com/joho/godotenv
Use the following command to clone this project
git clone git@github.com:zijuexiansheng/go-contacts.git
It is recommended to clone this project into your $GOPATH/src
directory. Some other untested approaches including adding the directory to your $GOPATH
, or use go mod
.
The server can be configured by changing the /path/to/repo/.env
file. The following parameters can be changed.
db_name
: the SQLite database name (default:gocontacts.db
)- You can copy the
default.db
in this repository to this name and run tests on it
- You can copy the
port
: (default:8000
)site_root
: the root path to the service (default:/go-dmo
)- This is how we defined
$SITEROOT
that will be used in the REST API and GraphQL below. - Suppose that the servers listens on
http://localhost:8000
site_root
is set to be/go-demo
$SITEROOT
will then behttp://localhost:8000/go-demo
$SITEROOT/api
will behttp://localhost:8000/go-demo/api
- This is how we defined
token_password
: A secret token password. Please set one by yourself. This password should be kept secretgraph_complexity
: The complexity of GraphQL queries (default:200
). This parameter is used to prevent heavy-loaded request that could overload the server, particularly the database systemtest_ql
: If set to1
, one can open the$SITEROOT
and test the GraphQL, as in the examples in the screenshots. If set to0
(default), then the$SITEROOT
will only return a greeting- N.B., for requests requiring authorizations, please use
curl
orPostman
to login and acquire the token first, and then add the token to the Header. See the "Authorization" in the "HTTP HEADERS" in gql-7 for an example (ignore the "Authorization-1" and "Authorization-3")
- N.B., for requests requiring authorizations, please use
- Go to the repository directory (make sure the directory is listed in the
$GOPATH
) - Copy the
default.db
to any database file name (saycp default.db gocontacts.db
) - Change the configuration file
/path/to/repo/.env
as you wish- and remember to change the
db_name
- and remember to change the
go run main.go
- Use
curl
orPostman
to test the REST API (also GraphQL) - If
test_ql = 1
, then you can go to$SITEROOT
and use the Playground to try with the GraphQL.- See screenshots for examples
- All the requests should go to
$SITEROOT/api/...
- To read the REST API, click here
- All the requests should go to
$SITEROOT/graphql
- To read the GraphQL schema, click here
- Visit here for some screenshots
MIT License