-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.go
65 lines (54 loc) · 2.43 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2023, Menahem-Mendel Gelfand. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file contains the definitions for the Driver interface and related types in the oci package.
// A Driver is the core interface in this package and is designed to enable interaction with different OCI implementations.
// Example usage:
// drv := oci.NewDriver()
// ctx := context.Background()
// conn, err := drv.Connect(ctx, "localhost:5000")
//
// if err != nil {
// log.Fatalf("Failed to connect: %v", err)
// }
//
// defer conn.Close()
package oci
import "context"
// Driver is an interface for handling communication with an OCI compatible runtime.
// It embeds the Connector interface and provides a Handler method.
type Driver interface {
// Connector provides a method for establishing a connection with an OCI compatible runtime.
Connector
// Handler returns a Handler based on the provided string (usually a method name).
Handler(string) Handler
}
// Conn is an interface for a connection to an OCI compatible runtime.
// It provides a method for closing the connection.
type Conn interface {
// Close closes the connection to an OCI compatible runtime.
// It should return an error if the connection cannot be closed.
Close() error
}
// Connector is an interface for establishing a connection with an OCI compatible runtime.
type Connector interface {
// Connect establishes a connection to an OCI compatible runtime based on the provided URI.
// The context is used to control cancellation of the connection process.
// It should return a Conn for the established connection or an error if the connection process fails.
Connect(ctx context.Context, uri string) (Conn, error)
}
// Handler is an interface for handling a request to an OCI compatible runtime.
// It provides a method for serving an OCI request.
type Handler interface {
// ServeOCI serves a Request to an OCI compatible runtime.
// It should return a Response or an error if the request fails.
ServeOCI(r *Request) (*Response, error)
}
// HandlerFunc is a function type that implements the Handler interface.
type HandlerFunc func(r *Request) (*Response, error)
// ServeOCI serves a Request to an OCI compatible runtime.
// It simply calls the function h with the request r.
// It returns a Response or an error if the request fails.
func (h HandlerFunc) ServeOCI(r *Request) (*Response, error) {
return h(r)
}