Created
June 10, 2018 06:49
-
-
Save hauxe/c9c2b6a882291e20a1b15596c6ea3ea6 to your computer and use it in GitHub Desktop.
crud register read handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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