-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ArtisanCloud/develop
Develop
- Loading branch information
Showing
12 changed files
with
227 additions
and
39 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package data | ||
|
||
import ( | ||
"bytes" | ||
"encoding/csv" | ||
"os" | ||
) | ||
|
||
func CSVEncode(arrayCSV [][]string) ([]byte, error) { | ||
|
||
buffer := new(bytes.Buffer) | ||
writer := csv.NewWriter(buffer) | ||
|
||
err := writer.WriteAll(arrayCSV) | ||
|
||
return buffer.Bytes(), err | ||
|
||
} | ||
|
||
func CSVEncodeToFile(arrayCSV [][]string, file *os.File) ( error) { | ||
|
||
writer := csv.NewWriter(file) | ||
|
||
err := writer.WriteAll(arrayCSV) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package data | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_CSVEncodeToFile(t *testing.T) { | ||
var csvStruct [][]string | ||
csvStruct = [][]string{ | ||
{"name", "address", "phone"}, | ||
{"Ram", "Tokyo", "1236524"}, | ||
{"Shaym", "Beijing", "8575675.484"}, | ||
} | ||
|
||
csvFile, err := os.Create("csv_test.csv") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
defer csvFile.Close() | ||
|
||
err = CSVEncodeToFile(csvStruct, csvFile) | ||
if err != nil { | ||
t.Error(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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gout | ||
|
||
import ( | ||
"github.com/ArtisanCloud/PowerLibs/object" | ||
"github.com/guonaihong/gout" | ||
) | ||
|
||
func ConvertHashMapToGoutMap(hashMap *object.HashMap) gout.H{ | ||
gMap:=gout.H{} | ||
for k,v :=range *hashMap{ | ||
gMap[k] = v | ||
} | ||
return gMap | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package object | ||
|
||
import ( | ||
"bytes" | ||
"encoding/gob" | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func EncodeToBytes(p interface{}) []byte { | ||
buf := bytes.Buffer{} | ||
enc := gob.NewEncoder(&buf) | ||
err := enc.Encode(p) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("uncompressed size (bytes): ", len(buf.Bytes())) | ||
return buf.Bytes() | ||
} |
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
Oops, something went wrong.