Skip to content

libcontainer: move example code out of README#5127

Merged
kolyshkin merged 1 commit into
opencontainers:mainfrom
kolyshkin:libct-ex
Feb 27, 2026
Merged

libcontainer: move example code out of README#5127
kolyshkin merged 1 commit into
opencontainers:mainfrom
kolyshkin:libct-ex

Conversation

@kolyshkin

@kolyshkin kolyshkin commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Example code in README is outdated (especially since cgroups is moved to a separate repository in #4638) and lacks proper import statements. And, since it is not code, it is hard to keep it up to date.

Let's move it out to the example_test.go file and refer to it. Note we still don't run it, but it will be compiled and linted in CI.

Closes: #4786

Fixes: #3863

Comment thread libcontainer/README.md Outdated

## Using libcontainer

For a brief overview of using libcontainer, see [example\_test.go](example_test.go).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
For a brief overview of using libcontainer, see [example\_test.go](example_test.go).
For a brief overview of using libcontainer, see [`example_test.go`](example_test.go).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This \ was deliberate, it escapes _ to ensure it's literal _ and not a special markdown character. In this case, it should work with or without escaping.

Yet, it's an issue with vim/nvim syntax/markdown.vim file which sometimes marks a lone unescaped _ as an error. It is not an error when inside [], but fixing it is beyond my abilities.

Removed.

Comment thread libcontainer/example_test.go Outdated
_ "github.com/opencontainers/runc/libcontainer/nsenter"
)

func ExampleContainer() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does godoc produce the output you'd like for this?

IIRC ExampleXyz functions normally get associated with the exported symbol Xyz -- so I think this will get associated with libcontainer.Container.

If you wanted to make it package-level, I think you need to call it Example_container or something similar (that's what encoding/json does, at least...).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Indeed, ExampleContainer will be associated with the Container type, which is not what I want here.

Changed to Example_container. The local rendering (with godoc) differs from what we see on pkg.go.dev, and I still don't like what I see (e.g. no imports), but it's definitely an improvement over having the code in md file.

@cyphar cyphar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the nit about godoc, LGTM.

Example code in README is outdated (especially since cgroups is moved to
a separate repository) and lacks proper import statements. And, since it
is not code, it is hard to keep it up to date.

Let's move it out to the example_test.go file and refer to it. Note we
still don't run it, but it will be compiled and linted in CI.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin merged commit ed6a3d6 into opencontainers:main Feb 27, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert libcontainer/README.md to doc.go

3 participants