@@ -28,6 +28,10 @@ func (h *ApplicationHandler) generateToken(compat bool) string {
2828}
2929
3030func (h * ApplicationHandler ) registerApplication (ctx * gin.Context , a * model.Application , u * model.User ) error {
31+ if a == nil || u == nil {
32+ return errors .New ("nil parameters provided" )
33+ }
34+
3135 log .L .Printf ("Registering application %s." , a .Name )
3236
3337 channelID , err := h .DP .RegisterApplication (a .ID , a .Name , u .MatrixID )
@@ -46,6 +50,10 @@ func (h *ApplicationHandler) registerApplication(ctx *gin.Context, a *model.Appl
4650}
4751
4852func (h * ApplicationHandler ) createApplication (ctx * gin.Context , u * model.User , name string , compat bool ) (* model.Application , error ) {
53+ if u == nil {
54+ return nil , errors .New ("nil parameters provided" )
55+ }
56+
4957 log .L .Printf ("Creating application %s." , name )
5058
5159 application := model.Application {}
@@ -71,6 +79,10 @@ func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User,
7179}
7280
7381func (h * ApplicationHandler ) deleteApplication (ctx * gin.Context , a * model.Application , u * model.User ) error {
82+ if a == nil || u == nil {
83+ return errors .New ("nil parameters provided" )
84+ }
85+
7486 log .L .Printf ("Deleting application %s (ID %d)." , a .Name , a .ID )
7587
7688 err := h .DP .DeregisterApplication (a , u )
@@ -87,6 +99,10 @@ func (h *ApplicationHandler) deleteApplication(ctx *gin.Context, a *model.Applic
8799}
88100
89101func (h * ApplicationHandler ) updateApplication (ctx * gin.Context , a * model.Application , updateApplication * model.UpdateApplication ) error {
102+ if a == nil || updateApplication == nil {
103+ return errors .New ("nil parameters provided" )
104+ }
105+
90106 log .L .Printf ("Updating application %s (ID %d)." , a .Name , a .ID )
91107
92108 if updateApplication .Name != nil {
@@ -186,7 +202,7 @@ func (h *ApplicationHandler) GetApplications(ctx *gin.Context) {
186202// @Router /application/{id} [get]
187203func (h * ApplicationHandler ) GetApplication (ctx * gin.Context ) {
188204 application , err := getApplication (ctx , h .DB )
189- if err != nil {
205+ if err != nil || application == nil {
190206 return
191207 }
192208
@@ -218,7 +234,7 @@ func (h *ApplicationHandler) GetApplication(ctx *gin.Context) {
218234// @Router /application/{id} [delete]
219235func (h * ApplicationHandler ) DeleteApplication (ctx * gin.Context ) {
220236 application , err := getApplication (ctx , h .DB )
221- if err != nil {
237+ if err != nil || application == nil {
222238 return
223239 }
224240
@@ -250,7 +266,7 @@ func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context) {
250266// @Router /application/{id} [put]
251267func (h * ApplicationHandler ) UpdateApplication (ctx * gin.Context ) {
252268 application , err := getApplication (ctx , h .DB )
253- if err != nil {
269+ if err != nil || application == nil {
254270 return
255271 }
256272
0 commit comments