This file contains 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
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"sync" | |
) |
This file contains 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) registerD() gomHTTP.ServerRoute { | |
// build create sql | |
crud.Config.sqlCRUDDelete = fmt.Sprintf(sqlCRUDDelete, crud.Config.TableName, | |
crud.Config.pk.name) | |
return gomHTTP.ServerRoute{ | |
Name: "crud_delete_" + crud.Config.TableName, | |
Method: http.MethodDelete, | |
Path: fmt.Sprintf("/%s", crud.Config.TableName), | |
Validators: []gomHTTP.ParamValidator{validatePrimaryKey(crud.Config.pk.index)}, | |
Handler: crud.handleDelete, |
This file contains 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) Delete(data interface{}) (int64, error) { | |
rv := reflect.ValueOf(data) | |
rv = reflect.Indirect(rv) | |
pk := rv.Field(crud.Config.pk.index) | |
if !pk.CanInterface() { | |
return 0, errors.Errorf("table %s with primary key has wrong interface type", | |
crud.Config.TableName, crud.Config.pk.index) | |
} | |
result, err := crud.Config.DB.Exec(crud.Config.sqlCRUDDelete, pk.Interface()) | |
if err != nil { |
This file contains 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) registerL() gomHTTP.ServerRoute { | |
// build list sql | |
fields := crud.Config.listFields | |
if len(fields) == 0 { | |
// allow update all fields | |
fields = crud.Config.fields | |
} | |
fieldNames := make([]string, len(fields)) | |
for i, field := range fields { | |
fieldNames[i] = field.name |
This file contains 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
// List lists data and paging the result | |
func (crud *CRUD) List(pageID, perPage int64) ([]interface{}, error) { | |
offset := (pageID - 1) * perPage | |
rows, err := crud.Config.DB.Queryx(crud.Config.sqlCRUDList, offset, perPage) | |
if err != nil { | |
return nil, errors.Wrap(err, "error crud list") | |
} | |
defer rows.Close() | |
result := []interface{}{} |
This file contains 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
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"strings" | |
) | |
func main() { |
This file contains 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
// FileSystem custom file system handler | |
type FileSystem struct { | |
fs http.FileSystem | |
} | |
// Open opens file | |
func (fs FileSystem) Open(path string) (http.File, error) { | |
f, err := fs.fs.Open(path) | |
if err != nil { | |
return nil, err |
This file contains 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
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"strings" | |
) | |
// FileSystem custom file system handler |
This file contains 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
package main | |
import ( | |
"log" | |
"sync" | |
) | |
func main() { | |
cond := sync.NewCond(&sync.Mutex{}) | |
var wg1 sync.WaitGroup |
This file contains 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
// OR function combines all signal from channels into a single channel with Or condition | |
func OR(channels ...<-chan interface{}) <-chan interface{} { | |
switch len(channels) { | |
case 0: | |
return nil | |
case 1: | |
return channels[0] | |
} | |
orDone := make(chan interface{}) | |
go func() { |