made the channel receive-only, introduced a vangen config ed
This commit is contained in:
parent
54018ecc42
commit
cd12b80170
|
@ -9,4 +9,6 @@ testdata
|
|||
# this is the binary
|
||||
go-jamming
|
||||
|
||||
vangen
|
||||
|
||||
*.sublime-workspace
|
||||
|
|
|
@ -2,6 +2,8 @@ package mf
|
|||
|
||||
import (
|
||||
"brainbaking.com/go-jamming/common"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
"willnorris.com/go/microformats"
|
||||
|
@ -39,6 +41,19 @@ type IndiewebData struct {
|
|||
Target string `json:"target"`
|
||||
}
|
||||
|
||||
func (id *IndiewebData) IsEmpty() bool {
|
||||
return id.Url == ""
|
||||
}
|
||||
|
||||
// RequireFromFile converts the file JSON contents into the indieweb struct.
|
||||
// This ignores read and marshall errors and returns an emtpy struct instead.
|
||||
func RequireFromFile(file string) *IndiewebData {
|
||||
indiewebData := &IndiewebData{}
|
||||
data, _ := ioutil.ReadFile(file)
|
||||
json.Unmarshal(data, indiewebData)
|
||||
return indiewebData
|
||||
}
|
||||
|
||||
func PublishedNow(utcOffset int) string {
|
||||
return common.Now().UTC().Add(time.Duration(utcOffset) * time.Minute).Format("2006-01-02T15:04:05")
|
||||
}
|
||||
|
|
|
@ -2,38 +2,32 @@ package load
|
|||
|
||||
import (
|
||||
"brainbaking.com/go-jamming/app/mf"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
)
|
||||
|
||||
// FromDisk assumes that params have already been validated.
|
||||
func FromDisk(domain string, dataPath string) mf.IndiewebDataResult {
|
||||
// assume that params have already been validated.
|
||||
loadPath := path.Join(dataPath, domain)
|
||||
info, _ := ioutil.ReadDir(loadPath)
|
||||
amountOfFiles := len(info)
|
||||
results := make(chan *mf.IndiewebData, amountOfFiles)
|
||||
|
||||
for _, file := range info {
|
||||
fileName := file.Name()
|
||||
go func() {
|
||||
data, _ := ioutil.ReadFile(path.Join(loadPath, fileName))
|
||||
indiewebData := &mf.IndiewebData{}
|
||||
json.Unmarshal(data, indiewebData)
|
||||
results <- indiewebData
|
||||
}()
|
||||
go func(fileName string) {
|
||||
results <- mf.RequireFromFile(path.Join(loadPath, fileName))
|
||||
}(file.Name())
|
||||
}
|
||||
|
||||
indiewebResults := gather(amountOfFiles, results)
|
||||
return mf.WrapResult(indiewebResults)
|
||||
}
|
||||
|
||||
func gather(amount int, results chan *mf.IndiewebData) []*mf.IndiewebData {
|
||||
func gather(amount int, results <-chan *mf.IndiewebData) []*mf.IndiewebData {
|
||||
var indiewebResults []*mf.IndiewebData
|
||||
for i := 0; i < amount; i++ {
|
||||
result := <-results
|
||||
// json marshal errors are ignored in the above scatter func.Highly unlikely, but still.
|
||||
if result.Url != "" {
|
||||
if !result.IsEmpty() {
|
||||
indiewebResults = append(indiewebResults, result)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"domain": "brainbaking.com",
|
||||
"repositories": [
|
||||
{
|
||||
"prefix": "go-jamming",
|
||||
"subs": [
|
||||
"app",
|
||||
"app/index",
|
||||
"app/mf",
|
||||
"app/pingback",
|
||||
"app/pingback/send",
|
||||
"app/rss",
|
||||
"app/webmention",
|
||||
"app/webmention/load",
|
||||
"app/webmention/recv",
|
||||
"app/webmention/send",
|
||||
"common",
|
||||
"rest"
|
||||
],
|
||||
"url": "https://github.com/wgroeneveld/go-jamming"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue