Skip to content

Commit 50c0a7b

Browse files
committed
initial
0 parents  commit 50c0a7b

11 files changed

Lines changed: 412 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
3+
version: 2
4+
updates:
5+
# Maintain dependencies for GitHub Actions
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
interval: "weekly"
10+
groups:
11+
all:
12+
patterns:
13+
- "*"
14+
15+
# Maintain dependencies for Golang
16+
- package-ecosystem: "gomod"
17+
directory: "/"
18+
schedule:
19+
interval: "monthly"
20+
groups:
21+
all:
22+
patterns:
23+
- "*"

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Unit Tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- latest
7+
pull_request:
8+
branches:
9+
- latest
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
name: Go unit tests
16+
steps:
17+
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
18+
19+
- name: Setup go
20+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
21+
with:
22+
go-version-file: ./go.mod
23+
24+
- name: Set up gotestfmt
25+
uses: gotesttools/gotestfmt-action@65f1d2228f06cc5e828b84597440fbd063d12ea2 # v2.1.0
26+
27+
- run: make unittest

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Felipe Martin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BASH ?= $(shell command -v bash 2> /dev/null)
2+
3+
# Testing
4+
GO_TEST_FLAGS ?= -v -race -count=1
5+
GOTESTFMT_FLAGS ?=
6+
7+
## Run unit tests
8+
.PHONY: unittest
9+
unittest:
10+
GO_TEST_FLAGS="$(GO_TEST_FLAGS)" GOTESTFMT_FLAGS="$(GOTESTFMT_FLAGS)" $(BASH) -xe ./scripts/test.sh

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# go-comicinfo
2+
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/fmartingr/go-comicinfo.svg)](https://pkg.go.dev/github.com/fmartingr/go-comicinfo)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/fmartingr/go-comicinfo)](https://goreportcard.com/report/github.com/fmartingr/go-comicinfo)
5+
[![codecov](https://codecov.io/gh/fmartingr/go-comicinfo/branch/master/graph/badge.svg?token=ZQZQZQZQZQ)](https://codecov.io/gh/fmartingr/go-comicinfo)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
8+
Golang implementation of the [ComicInfo.xml specification](https://anansi-project.github.io/docs/category/comicinfo) to read and write `comicinfo.xml` files.
9+
10+
11+
## Contributing
12+
13+
Contributions are welcome, please open an issue or a pull request.
14+
15+
## Versioning
16+
17+
This project uses [Semantic Versioning](https://semver.org/) and will follow the major and minor versions of the [ComicInfo.xml specification](https://anansi-project.github.io/docs/category/comicinfo), while using the hotfix version for any changes to the library itself.
18+
19+
## Usage example
20+
21+
```go
22+
package main
23+
24+
import "github.com/fmartingr/go-comicinfo/v2"
25+
26+
func main() {
27+
ci := comicinfo.NewComicInfo()
28+
ci.Series = "One Piece"
29+
ci.Number = "3093"
30+
ci.Summary = "Luffy and the Straw Hat Pirates return in an all-new Epic Voyage!"
31+
ci.AgeRating = comicinfo.AgeRatingEveryone
32+
ci.LanguageISO = "en"
33+
34+
for i := 1; i <= 17; i++ {
35+
ci.Pages.Pages = append(ci.Pages.Pages, comicinfo.ComicPageInfo{
36+
Image: i,
37+
})
38+
}
39+
40+
_ = comicinfo.Write(ci, "volume/comicinfo.xml")
41+
}
42+
```
43+
44+
Result
45+
46+
```xml
47+
<?xml version="1.0" encoding="UTF-8"?>
48+
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema"
49+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
50+
<Series>One Piece</Series>
51+
<Number>3093</Number>
52+
<Summary>Luffy and the Straw Hat Pirates return in an all-new Epic Voyage!</Summary>
53+
<LanguageISO>en</LanguageISO>
54+
<AgeRating>Everyone</AgeRating>
55+
<Pages>
56+
<Page Image="1"></Page>
57+
<Page Image="2"></Page>
58+
<Page Image="3"></Page>
59+
<Page Image="4"></Page>
60+
<Page Image="5"></Page>
61+
<Page Image="6"></Page>
62+
<Page Image="7"></Page>
63+
<Page Image="8"></Page>
64+
<Page Image="9"></Page>
65+
<Page Image="10"></Page>
66+
<Page Image="11"></Page>
67+
<Page Image="12"></Page>
68+
<Page Image="13"></Page>
69+
<Page Image="14"></Page>
70+
<Page Image="15"></Page>
71+
<Page Image="16"></Page>
72+
<Page Image="17"></Page>
73+
</Pages>
74+
</ComicInfo>
75+
76+
```
77+
78+
## License
79+
80+
[MIT LICENSE](LICENSE)

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/fmartingr/go-comicinfo/v2
2+
3+
go 1.21.1
4+
5+
require github.com/stretchr/testify v1.8.4
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
6+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

io.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package comicinfo
2+
3+
import (
4+
"bytes"
5+
"encoding/xml"
6+
"fmt"
7+
"os"
8+
)
9+
10+
// Write writes the ComicInfo spec to the specified path.
11+
func Write(ci ComicInfo, path string) error {
12+
contents, err := xml.Marshal(ci)
13+
if err != nil {
14+
return fmt.Errorf("error marshalling ComicInfo: %w", err)
15+
}
16+
17+
err = os.WriteFile(path, bytes.Join([][]byte{xmlHeader, contents}, []byte("")), 0644)
18+
if err != nil {
19+
return fmt.Errorf("error writing ComicInfo to file: %w", err)
20+
}
21+
return nil
22+
}
23+
24+
// Read reads the ComicInfo spec from the specified path.
25+
func Read(path string) (ComicInfo, error) {
26+
f, err := os.ReadFile(path)
27+
if err != nil {
28+
return ComicInfo{}, fmt.Errorf("error reading file: %w", err)
29+
}
30+
31+
var ci ComicInfo
32+
err = xml.Unmarshal(f, &ci)
33+
if err != nil {
34+
return ComicInfo{}, fmt.Errorf("error unmarshalling ComicInfo: %w", err)
35+
}
36+
37+
return ci, nil
38+
}

io_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package comicinfo
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestWriteRead(t *testing.T) {
11+
tmpDir := t.TempDir()
12+
ci := ComicInfo{
13+
Title: "Test",
14+
}
15+
16+
path := filepath.Join(tmpDir, "test.xml")
17+
18+
err := Write(ci, path)
19+
if err != nil {
20+
t.Errorf("error writing ComicInfo: %v", err)
21+
}
22+
23+
ci2, err := Read(path)
24+
if err != nil {
25+
t.Errorf("error reading ComicInfo: %v", err)
26+
}
27+
28+
require.Equal(t, ci, ci2)
29+
}

0 commit comments

Comments
 (0)