implemented webServer, and implemented listPadsImporter

This commit is contained in:
arnaucode
2018-04-15 00:21:36 +02:00
parent 3691547c68
commit 3e0ef09e55
19 changed files with 420 additions and 5 deletions

View File

@@ -0,0 +1,9 @@
package main
import "github.com/fatih/color"
func check(err error) {
if err != nil {
color.Red(err.Error())
}
}

View File

@@ -0,0 +1,20 @@
{
"repoid": "repo01",
"pads": [
{
"link": "http://board.net/p/pad1",
"dir": "Group1",
"title": "Pad1"
},
{
"link": "http://board.net/p/pad2",
"dir": "Group1",
"title": "Pad2"
},
{
"link": "http://board.net/p/pad3",
"dir": "Group2",
"title": "Pad3"
}
]
}

BIN
listPadsImporter/listPadsImporter Executable file

Binary file not shown.

66
listPadsImporter/main.go Normal file
View File

@@ -0,0 +1,66 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
padArchiver ".."
"github.com/fatih/color"
)
type PadModel struct {
Link string `json:"link"`
Dir string `json:"dir"`
Title string `json:"title"`
}
type ListModel struct {
RepoID string `json:"repoid"`
Pads []PadModel `json:"pads"`
}
func readList(path string) ListModel {
file, err := ioutil.ReadFile(path)
check(err)
content := string(file)
var list ListModel
json.Unmarshal([]byte(content), &list)
return list
}
func main() {
asciiart := `
.
. _ _ _
. | | /\ | | (_)
_ __ __ _ __| | / \ _ __ ___| |__ ___ _____ _ __
| '_ \ / _ |/ _ | / /\ \ | '__/ __| '_ \| \ \ / / _ \ '__|
| |_) | (_| | (_| |/ ____ \| | | (__| | | | |\ V / __/ |
| .__/ \__,_|\__,_/_/ \_\_| \___|_| |_|_| \_/ \___|_| - listPadsImporter
| |
|_|
`
color.Blue(asciiart)
fmt.Println(" v0.0.1")
color.Blue("https://github.com/arnaucode/padArchiver")
fmt.Println("")
fmt.Println("")
fmt.Println("")
list := readList("list.json")
//open the repo
repo := padArchiver.OpenRepo(list.RepoID)
fmt.Println("repo opened")
for _, pad := range list.Pads {
fmt.Println("importing pad:")
fmt.Println(" link: " + pad.Link)
fmt.Println(" dir: " + pad.Dir)
fmt.Println(" title: " + pad.Title)
ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title)
check(err)
fmt.Println(" ipfs hash: " + ipfsHash)
}
color.Green("listPadsImporter finished")
}