Documentation
¶
Overview ¶
Package olareg is used for running a minimal OCI conformant container registry.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
LogTrace = slog.LevelDebug - 4
)
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
New returns a Server. Ensure the resource is cleaned up with either Server.Close or Server.Shutdown.
Example (Directory) ¶
package main
import (
"context"
"fmt"
"os"
"github.com/olareg/olareg"
"github.com/olareg/olareg/config"
)
func main() {
ctx := context.Background()
// create a server backed by a local directory, listening on port 5000
regHandler := olareg.New(config.Config{
HTTP: config.ConfigHTTP{
Addr: ":5000",
},
Storage: config.ConfigStorage{
StoreType: config.StoreDir,
RootDir: "/path/to/storage",
},
})
// run the server
err := regHandler.Run(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "startup failed: %v", err)
return
}
// use the server
// ...
// shutdown the server
err = regHandler.Shutdown(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "shutdown failed: %v", err)
return
}
}
Output:
Example (Mem) ¶
package main
import (
"context"
"fmt"
"os"
"github.com/olareg/olareg"
"github.com/olareg/olareg/config"
)
func main() {
ctx := context.Background()
// create a server backed by memory, listening on port 5000
regHandler := olareg.New(config.Config{
HTTP: config.ConfigHTTP{
Addr: ":5000",
},
Storage: config.ConfigStorage{
StoreType: config.StoreMem,
},
})
// run the server
err := regHandler.Run(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "startup failed: %v", err)
return
}
// use the server
// ...
// shutdown the server
err = regHandler.Shutdown(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "shutdown failed: %v", err)
return
}
}
Output:
Example (Test) ¶
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"github.com/olareg/olareg"
"github.com/olareg/olareg/config"
)
func main() {
ctx := context.Background()
// create a new olareg handler backed by memory
regHandler := olareg.New(config.Config{
Storage: config.ConfigStorage{
StoreType: config.StoreMem,
},
})
// start the handler using httptest for unit tests
ts := httptest.NewServer(regHandler)
defer ts.Close()
defer regHandler.Close()
// ping the /v2/ endpoint
u, err := url.Parse(ts.URL)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse url: %v", err)
return
}
u.Path = "/v2/"
req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to generate request: %v", err)
return
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to send request: %v", err)
return
}
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read body: %v", err)
return
}
fmt.Printf("body: %s\n", string(body))
}
Output: body: {}
func (*Server) Run ¶
Run starts a listener and serves requests. It only returns after a call to Server.Shutdown.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
olareg
command
|
|
|
Package config contains data types for configuration of olareg.
|
Package config contains data types for configuration of olareg. |
|
internal
|
|
|
cache
Package cache is used to store values with limits.
|
Package cache is used to store values with limits. |
|
cobradoc
Package cobradoc is used to generate documentation from cobra commands.
|
Package cobradoc is used to generate documentation from cobra commands. |
|
copy
Package copy is used internally to recursively copy filesystem content.
|
Package copy is used internally to recursively copy filesystem content. |
|
godbg
Package godbg provides tooling for debugging Go
|
Package godbg provides tooling for debugging Go |
|
httplog
Package httplog provides a log/slog logging middleware for http servers.
|
Package httplog provides a log/slog logging middleware for http servers. |
|
sloghandle
Package sloghandle includes handlers for slog.
|
Package sloghandle includes handlers for slog. |
|
store
Package store is used to interface with different types of storage (memory, disk)
|
Package store is used to interface with different types of storage (memory, disk) |
|
template
Package template wraps a common set of templates around text/template
|
Package template wraps a common set of templates around text/template |
|
version
Package version returns details on the Go and Git repo used in the build
|
Package version returns details on the Go and Git repo used in the build |
|
Package types contains various data types and well known constants.
|
Package types contains various data types and well known constants. |
Click to show internal directories.
Click to hide internal directories.