-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2fd71f8
Showing
11 changed files
with
412 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
groups: | ||
all: | ||
patterns: | ||
- "*" | ||
|
||
# Maintain dependencies for Golang | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "monthly" | ||
groups: | ||
all: | ||
patterns: | ||
- "*" |
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,27 @@ | ||
name: "Unit Tests" | ||
|
||
on: | ||
push: | ||
branches: | ||
- latest | ||
pull_request: | ||
branches: | ||
- latest | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
name: Go unit tests | ||
steps: | ||
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
|
||
- name: Setup go | ||
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 | ||
with: | ||
go-version-file: ./go.mod | ||
|
||
- name: Set up gotestfmt | ||
uses: gotesttools/gotestfmt-action@65f1d2228f06cc5e828b84597440fbd063d12ea2 # v2.1.0 | ||
|
||
- run: make unittest |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 anansi-project | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,10 @@ | ||
BASH ?= $(shell command -v bash 2> /dev/null) | ||
|
||
# Testing | ||
GO_TEST_FLAGS ?= -v -race -count=1 | ||
GOTESTFMT_FLAGS ?= | ||
|
||
## Run unit tests | ||
.PHONY: unittest | ||
unittest: | ||
GO_TEST_FLAGS="$(GO_TEST_FLAGS)" GOTESTFMT_FLAGS="$(GOTESTFMT_FLAGS)" $(BASH) -xe ./scripts/test.sh |
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,80 @@ | ||
# go-comicinfo | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/fmartingr/go-comicinfo.svg)](https://pkg.go.dev/github.com/fmartingr/go-comicinfo) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/fmartingr/go-comicinfo)](https://goreportcard.com/report/github.com/fmartingr/go-comicinfo) | ||
[![codecov](https://codecov.io/gh/fmartingr/go-comicinfo/branch/master/graph/badge.svg?token=ZQZQZQZQZQ)](https://codecov.io/gh/fmartingr/go-comicinfo) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
|
||
Golang implementation of the [ComicInfo.xml specification](https://anansi-project.github.io/docs/category/comicinfo) to read and write `comicinfo.xml` files. | ||
|
||
|
||
## Contributing | ||
|
||
Contributions are welcome, please open an issue or a pull request. | ||
|
||
## Versioning | ||
|
||
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. | ||
|
||
## Usage example | ||
|
||
```go | ||
package main | ||
|
||
import "github.com/fmartingr/go-comicinfo/v2" | ||
|
||
func main() { | ||
ci := comicinfo.NewComicInfo() | ||
ci.Series = "One Piece" | ||
ci.Number = "3093" | ||
ci.Summary = "Luffy and the Straw Hat Pirates return in an all-new Epic Voyage!" | ||
ci.AgeRating = comicinfo.AgeRatingEveryone | ||
ci.LanguageISO = "en" | ||
|
||
for i := 1; i <= 17; i++ { | ||
ci.Pages.Pages = append(ci.Pages.Pages, comicinfo.ComicPageInfo{ | ||
Image: i, | ||
}) | ||
} | ||
|
||
_ = comicinfo.Write(ci, "volume/comicinfo.xml") | ||
} | ||
``` | ||
|
||
Result | ||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<Series>One Piece</Series> | ||
<Number>3093</Number> | ||
<Summary>Luffy and the Straw Hat Pirates return in an all-new Epic Voyage!</Summary> | ||
<LanguageISO>en</LanguageISO> | ||
<AgeRating>Everyone</AgeRating> | ||
<Pages> | ||
<Page Image="1"></Page> | ||
<Page Image="2"></Page> | ||
<Page Image="3"></Page> | ||
<Page Image="4"></Page> | ||
<Page Image="5"></Page> | ||
<Page Image="6"></Page> | ||
<Page Image="7"></Page> | ||
<Page Image="8"></Page> | ||
<Page Image="9"></Page> | ||
<Page Image="10"></Page> | ||
<Page Image="11"></Page> | ||
<Page Image="12"></Page> | ||
<Page Image="13"></Page> | ||
<Page Image="14"></Page> | ||
<Page Image="15"></Page> | ||
<Page Image="16"></Page> | ||
<Page Image="17"></Page> | ||
</Pages> | ||
</ComicInfo> | ||
|
||
``` | ||
|
||
## License | ||
|
||
[MIT LICENSE](LICENSE) |
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,11 @@ | ||
module github.com/fmartingr/go-comicinfo/v2 | ||
|
||
go 1.21.1 | ||
|
||
require github.com/stretchr/testify v1.8.4 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,38 @@ | ||
package comicinfo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Write writes the ComicInfo spec to the specified path. | ||
func Write(ci ComicInfo, path string) error { | ||
contents, err := xml.Marshal(ci) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling ComicInfo: %w", err) | ||
} | ||
|
||
err = os.WriteFile(path, bytes.Join([][]byte{xmlHeader, contents}, []byte("")), 0644) | ||
if err != nil { | ||
return fmt.Errorf("error writing ComicInfo to file: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
// Read reads the ComicInfo spec from the specified path. | ||
func Read(path string) (ComicInfo, error) { | ||
f, err := os.ReadFile(path) | ||
if err != nil { | ||
return ComicInfo{}, fmt.Errorf("error reading file: %w", err) | ||
} | ||
|
||
var ci ComicInfo | ||
err = xml.Unmarshal(f, &ci) | ||
if err != nil { | ||
return ComicInfo{}, fmt.Errorf("error unmarshalling ComicInfo: %w", err) | ||
} | ||
|
||
return ci, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package comicinfo | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriteRead(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
ci := ComicInfo{ | ||
Title: "Test", | ||
} | ||
|
||
path := filepath.Join(tmpDir, "test.xml") | ||
|
||
err := Write(ci, path) | ||
if err != nil { | ||
t.Errorf("error writing ComicInfo: %v", err) | ||
} | ||
|
||
ci2, err := Read(path) | ||
if err != nil { | ||
t.Errorf("error reading ComicInfo: %v", err) | ||
} | ||
|
||
require.Equal(t, ci, ci2) | ||
} |
Oops, something went wrong.