Skip to content

Public Interafce redesing #483

@Tinyblargon

Description

@Tinyblargon

Currently we have a lot of public functions, lots of them are functions on types.
But in my opinion we don't have consistent way to interact with any of those functions.

My proposal is to introduce the following structure. Everything flows out of the Client, we have sub categories like Guest and QemuGuest, which then have functions to interact with the API.

type ClientConfig struct {
}

func (c ClientConfig) New() (*ClientNewNew, error) {
	client := &clientAPI{}
	return &ClientNewNew{
		Guest:     &guestInterface{c: client},
		QemuGuest: &qemuGuestInterface{c: client},
	}, nil
}

type ClientNewNew struct {
	Guest     GuestInterface
	QemuGuest QemuGuestInterface
}

type (
	// Interface to interact with Qemu and Lxc guests.
	GuestInterface interface {
		List(context.Context) (RawGuestResources, error)
	}
	guestInterface struct {
		c clientApiInterface
	}
)

func (i guestInterface) List(ctx context.Context) (RawGuestResources, error) {
	return nil, nil
}

type (
	// Interface to interact with Qemu guests.
	QemuGuestInterface interface {
		Create(context.Context, ConfigQemu) error
		Start(context.Context, VmRef) error
	}
	qemuGuestInterface struct {
		c clientApiInterface
	}
)

func (i *qemuGuestInterface) Create(ctx context.Context, config ConfigQemu) error {
	return nil
}

func (i *qemuGuestInterface) Start(ctx context.Context, guest VmRef) error {
	return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions