diff --git a/README.md b/README.md index 918ab41..438d9a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # code2img [![PkgGoDev](https://pkg.go.dev/badge/golang.design/x/code2img)](https://pkg.go.dev/golang.design/x/code2img) ![](https://changkun.de/urlstat?mode=github&repo=golang-design/code2img) -a carbon service wrapper +a carbon service wrapper for Go users ```go import "golang.design/x/code2img" @@ -8,16 +8,9 @@ import "golang.design/x/code2img" ## API Usage -Just one API `code2img.Render`, to use it: +Just one API `code2img.Render`, to use it (see [main.go](./example/main.go)): -```go -b, err := code2img.Render(context.TODO(), `import "golang.design/x/code2img"`) -if err != nil { - panic(err) -} - -os.WriteFile("code.png", b, os.ModePerm) -``` +![](./example/code.png) ## Service Usage diff --git a/code2img_test.go b/code2img_test.go index df71c17..6550e8d 100644 --- a/code2img_test.go +++ b/code2img_test.go @@ -22,7 +22,7 @@ func TestRender(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - got, err := code2img.Render(ctx, `import "golang.design/x/code2img`) + got, err := code2img.Render(ctx, `import "golang.design/x/code2img"`) if err != nil { t.Fatalf("render failed: %v", err) } diff --git a/example/code.png b/example/code.png new file mode 100644 index 0000000..89389a3 Binary files /dev/null and b/example/code.png differ diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..d7ee9be --- /dev/null +++ b/example/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "context" + "os" + + "golang.design/x/code2img" +) + +func main() { + f, err := os.ReadFile("main.go") + if err != nil { + panic(err) + } + code := string(f) + + // render it! + b, err := code2img.Render(context.TODO(), code) + if err != nil { + panic(err) + } + + os.WriteFile("code.png", b, os.ModePerm) +} diff --git a/testdata/got.png b/testdata/got.png deleted file mode 100755 index c024acb..0000000 Binary files a/testdata/got.png and /dev/null differ diff --git a/testdata/want.png b/testdata/want.png index f19749a..004beb4 100755 Binary files a/testdata/want.png and b/testdata/want.png differ