Skip to content

Instantly share code, notes, and snippets.

@hauxe
Created June 10, 2018 06:49
Show Gist options
  • Save hauxe/c9c2b6a882291e20a1b15596c6ea3ea6 to your computer and use it in GitHub Desktop.
Save hauxe/c9c2b6a882291e20a1b15596c6ea3ea6 to your computer and use it in GitHub Desktop.
crud register read handler
func (crud *CRUD) registerR() gomHTTP.ServerRoute {
// build select sql
fields := crud.Config.selectFields
if len(fields) == 0 {
// allow select all fields
fields = crud.Config.fields
}
fieldNames := make([]string, len(fields))
for i, field := range fields {
fieldNames[i] = field.name
}
crud.Config.selectedFields = fields
crud.Config.sqlCRUDRead = fmt.Sprintf(sqlCRUDRead, strings.Join(fieldNames, ","),
crud.Config.TableName, crud.Config.pk.name)
return gomHTTP.ServerRoute{
Name: "crud_read_" + crud.Config.TableName,
Method: http.MethodGet,
Path: fmt.Sprintf("/%s", crud.Config.TableName),
Validators: []gomHTTP.ParamValidator{validatePrimaryKey(crud.Config.pk.index)},
Handler: crud.handleRead,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment