Categorygithub.com/thomas-bouvier/insapp-go
modulepackage
0.0.0-20200317174444-9ea8f80d35d1
Repository: https://github.com/thomas-bouvier/insapp-go.git
Documentation: pkg.go.dev

# README

insapp-go

Go Report Card

Backend part of Insapp written in Go

Installation

go get

go get github.com/thomas-bouvier/insapp-go/...

API

Check that you have MongoDB running.

insapp-api

The process is listening on 0.0.0.0:9000 by default.

CLI

insapp-cli

Docker

Build

docker build -t insapp-go .

Run

docker run -it insapp-go

To ssh into this container, use the following command:

docker exec -it insapp-go ash

Configuration

Edit the configuration file:

cp config.json.dist config.json
vi config.json

Attributes google_email and google_password refer to the credentials of your Google account. These credentials are used to send emails. mongo_password refers to the MongoDB password. env refers to the environment type and should be set to prod, dev or local. Finally, port refers to the API port.

In a local environment:

  • Cookies are not secure ;
  • Push notifications are not sent.

The FCM HTTP v1 API requires some credentials to send push notifications. The service-account.json file can be downloaded from the Firebase Cloud Messaging dashboard, and should be copied at the root of this directory. This way, it will be included in the Docker container.

The authentication mechanism relies on JWT tokens and thus needs a secret key. Please generate the following keys at the root of this directory:

openssl genrsa -out app.rsa 2048
openssl rsa -in app.rsa -pubout > app.rsa.pub

API Endpoints

Public routes

TypeEndpoint callsDescription
GET/Index
GET/how-to-postGet the tutorial for posting content
GET/creditGet the credits
GET/legalGet the legal conditions
POST/login/associationLog an association in
POST/login/user/{ticket}Log a user in with the ticket {ticket} provided by CAS

User routes

TypeEndpoint callsDescription
GET/associationsGet all associations
GET/associations/{id}Get the association with id {id}
GET/associations/{id}/eventsGet all events of the association with id {id}
GET/associations/{id}/postsGet all posts of the association with id {id}
GET/eventsGet all future events
GET/events/{id}Get the event with id {id}
POST/events/{id}/attend/{userID}/status/{status}Post the attendee status {status} for the user with id {userID} on the event with id {id}
DELETE/events/{id}/attend/{userID}Delete the attendee status of the user with id {userID} on the event with id {id}
POST/events/{id}/commentPost a comment on the event with id {id}
DELETE/events/{id}/comment/{commentID}Delete the comment with id {commentID} on the event with id {id}
GET/postsGet all posts. You can provide ?range=[{start},{count}] to get only some posts
GET/posts/{id}Get the post with id {id}
POST/posts/{id}/like/{userID}Post a like for the user with id {userID} on the post with id {id}
DELETE/posts/{id}/like/{userID}Post an unlike for the user with id {userID} on the post with id {id}
POST/posts/{id}/commentPost a comment on the post with id {id}
DELETE/posts/{id}/comment/{commentID}Delete the comment with id {commentID} on the post with id {id}
GET/users/{id}Get the user with id {id}
PUT/users/{id}Update the user with id {id}
DELETE/users/{id}Delete the user with id {id}
POST/notificationsCreate a notification
GET/notifications/{userID}Get all notifications of the user with id {userID}
DELETE/notifications/{userID}/{id}Delete the notification with id {id} for the user with id {userID}
PUT/report/user/{userID}Report the user with id {userID}
PUT/report/{postID}/comment/{commentID}Report the comment with id {commentID} on the post with id {postID}
POST/searchSearch for users, associations, events and posts
POST/search/usersSearch for users
POST/search/associationsSearch for associations
POST/search/eventsSearch for events
POST/search/postsSearch for posts
POST/logout/userLogout the current user

Association routes

TypeEndpoint callsDescription
GET/associationGet the current association
PUT/associations/{id}Update the association with id {id}
POST/eventsCreate an event
PUT/events/{id}Update the event with id {id}
DELETE/events/{id}Delete the event with id {id}
POST/postsCreate a post
PUT/posts/{id}Update the post with id {id}
DELETE/posts/{id}Delete the post with id {id}
POST/imagesPost an image
POST/logout/associationLogout the current association user

Super user routes

TypeEndpoint callsDescription
POST/associationsCreate an association
DELETE/associations/{id}Delete the association with id {id}
GET/associations/{ownerID}/myassociationsGet the associations owned by the association with id {ownerID}
GET/usersGet all users

# Packages

No description provided by the author

# Functions

AddAssociation will add the given Association to the database.
AddAssociationController will answer a JSON of the brand new created association (from the JSON Body) Should be protected.
AddAssociationUser will add the given AssociationUser to the database.
No description provided by the author
AddAttendeeToGoingList will add the given userID to the given eventID as an attendee.
No description provided by the author
No description provided by the author
AddEvent will add the Event event to the database.
AddEventController will answer the JSON of the brand new created Event from the JSON body Should be protected.
AddEventToAssociation will add the given event ID to the given association.
AddEventToUser will add the eventID to the list of the user's event linked to the given id.
No description provided by the author
AddPost will add the given Post to the database.
AddPostController will answer a JSON of the brand new created post (from the JSON Body) Should be protected.
No description provided by the author
AddUser will add the given user from JSON body to the database.
AddUserController will answer a JSON of the brand new created user (from the JSON Body).
ArchiveImage will move images in a subdirectory "archive".
AuthMiddleware makes sure the user is authenticated before handling the request.
AddAttendeeController will answer the JSON of the event with the given attendee added.
CheckAndRefreshStringTokens renews the auth token, if needed.
No description provided by the author
CommentEventController will answer a JSON of the event.
CommentPost will add the given comment object to the list of comments of the post linked to the given id.
CommentPostController will answer a JSON of the post.
ContainsString returns true if slice contains element.
CreateNewTokens creates auth and refresh tokens.
No description provided by the author
Credit show a credit page.
DeleteAssociation will delete the given association from the database.
DeleteAssociationController will answer a JSON of an empty association if the deletion has succeed Should be protected.
No description provided by the author
No description provided by the author
DeleteEvent will delete the given Event.
DeleteEventController will answer an empty JSON if the deletion has succeed Should be protected.
DeleteImage will permanently delete an image.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeletePost will delete the given Post from the database.
DeletePostController will answer a JSON of an empty post if the deletion has succeed Should be protected.
No description provided by the author
No description provided by the author
DeleteTokenCookies deletes the cookies.
DeleteUser will delete the given user from the database.
DeleteUserController will answer a JSON of an empty user if the deletion succeeded.
DislikePost will remove the postID from the list of liked post of the user linked to the given id.
DislikePostController will answer a JSON of the post and the user that disliked the post.
DislikePostWithUser will remove the user to the list of users that liked the post (cf.
No description provided by the author
GenerateRandomBytes returns securely generated random bytes.
GenerateRandomString returns a URL-safe, base64 encoded securely generated random string.
GetAllAssociations will return an array of all the existing Association, hidding "Menu" association and sort by name asc.
GetAllAssociationsController will answer a JSON of all associations.
GetAllPostsController will answer a JSON of the N latest posts.
GetAllUser will return an User object from the given ID.
No description provided by the author
GetAssociation will return an Association object from the given ID.
GetAssociationController will answer a JSON of the association linked to the given id in the URL.
GetAssociationFromEmail will return an Association object from the given email.
GetAssociationUser return the AssociationUser object with the given ID.
No description provided by the author
No description provided by the author
No description provided by the author
GetEvent returns an Event object from the given ID.
GetEventController will answer a JSON of the event from the given "id" in the URL.
GetEvents returns an array of Events.
GetEventsForAssociation returns an array of all Events from the given association ID.
No description provided by the author
GetFutureEvents returns an array of Event that will happen after "NOW".
GetFutureEventsController will answer a JSON containing all future events from "NOW".
GetImageColors will return a palette of colors found in the image.
GetImageDimension will return image dimention in pixels.
GetImagesNames will return a string of all images in cdn.
GetLatestPosts will return an array of the last N Posts.
No description provided by the author
GetMongoSession creates a new session.
GetMyAssociationController will answer a JSON of the associations owned by the applicant master association.
GetMyAssociations will return an array of all ID from owned existing Association.
No description provided by the author
No description provided by the author
No description provided by the author
GetPost will return a Post object from the given ID.
GetPostController will answer a JSON of the post linked to the given id in the URL.
GetPosts will return an array of Posts.
GetPostsForAssociation returns an array of Posts from the given association ID.
GetPostsForAssociationController will answer a JSON of the post owned by the given association.
No description provided by the author
GetUser return the User object with the given ID.
GetUserController will answer a JSON of the user linked to the given id in the URL.
GetUserFromRequest returns the User or AssociationUser ID from the auth cookie.
HowToPost show a page explaining how to post for associations.
Index is just a test actually.
InitConfig loads the configuration from the filesystem.
InitJWT reads the key files before starting http handlers.
Legal show a legal page.
LikePost will add the postID to the list of liked post of the user linked to the given id.
LikePostController will answer a JSON of the post and the user that liked the post.
LikePostWithUser will add the user to the list of user that liked the post (cf.
LoginAssociationController logs an association in.
LoginUserController logs a user in using CAS.
LogoutAssociationController logs an association out.
LogoutUserController logs a user out.
NewRouter is the constructor of the Router It will create every routes from the routes variable just above.
NewUser creates a new User.
No description provided by the author
No description provided by the author
RemoveAttendee remove the given userID from the given eventID as a participant.
RemoveAttendeeController will answer the JSON of the event without the given attendee added.
RemoveEventFromAssociation will remove the given event ID from the given association.
RemoveEventFromUser will remove the eventID from the list of the user's event linked to the given ID.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ResizeImage will resize an image as jpeg and response its new name Put 0 to newWidth or newHeight to make it automatically calculate to keep aspect ratio.
ResponseHandler will response to the client.
RevokeRefreshStringToken deletes the given token from the database, if valid.
SearchAssociation return an array of all Association found with the given search string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SendAssociationEmailForCommentOnEvent sends an email indicating a new comment has been added on an event.
SendAssociationEmailForCommentOnPost sends an email indicating a new comment has been added on a post.
SendAssociationEmailSubscription sends a subscription email containing the credentials.
SendEmail sends an email to the given recipient.
TriggerNotificationForEvent sends a notification and a push notification to users targeted by the promotion.
TriggerNotificationForPost sends a notification and a push notification to users targeted by the promotion.
TriggerNotificationForUserFromEvent sends a notification and a push notification to the given user.
TriggerNotificationForUserFromPost sends a notification and a push notification to the given user.
No description provided by the author
UncommentEventController will answer a JSON of the event.
UncommentPost will remove the given comment object from the list of comments of the post linked to the given id.
UncommentPostController will answer a JSON of the post Should be protected.
UpdateAssociation will update the given Association link to the given ID, with the field of the given Association, in the database.
UpdateAssociationController will answer the JSON of the modified association (from the JSON Body) Should be protected.
UpdateEvent will update the Event event in the database.
UpdateEventController will answer the JSON of the modified Event from the JSON body Should be protected.
No description provided by the author
UpdatePost will update the post linked to the given ID, with the field of the given post, in the database.
UpdatePostController will answer the JSON of the modified post (from the JSON Body) Should be protected.
UpdateUser will update the user link to the given ID, with the field of the given user, in the database.
UpdateUserController will answer the JSON of the modified user (from the JSON Body) Should be protected.
UploadImage will give a random name and upload the image.
UploadImageController will upload a new image in the cdn.
UploadImageWithName will manage the upload image from a POST request.
UploadNewImageController will upload a new image in the cdn.
VerifyEmail return true if email is not already used.

# Structs

Association defines the model of a Association.
AssociationLogin is the data provided by an association to authenticate.
AssociationUser defines how to model an AssociationUser.
Comment defines how to model a Comment of a Post.
Config defines how to model a Config.
Event defines what an Event is.
Notification defines how to model a Notification.
NotificationUser defines how to model a NotificationUser.
Post
Post defines how to model a Post.
Route type is used to define a route of the API.
No description provided by the author
No description provided by the author
TokenClaims is the JWT encoding format.
TokenJTI models JTI keeping track of tokens.
User defines how to model a User.

# Type aliases

Associations is an array of Association.
Comments is an array of Comment.
Events is an array of Event.
Middleware is the type wrapping http handlers.
No description provided by the author
Posts is an array of Post.
Routes type is an array of Route.
No description provided by the author
Users is an array of User.