Code Monkey home page Code Monkey logo

Comments (6)

barakmich avatar barakmich commented on May 16, 2024

That's pretty good. I'd combine those string arguments to a struct, but that's just me:

RegisterThirdPartyResource(ThirdPartyResourceType, interface{})

and

type ThirdPartyResourceType struct {
ApiGroup string
ApiVersion string
Plural string
}

from k8s.

ericchiang avatar ericchiang commented on May 16, 2024

I think register isn't going to work. Mostly because things like Delete doesn't take a struct argument so there's nothing to reflect and map.

Current working on something like:

func (t *ThirdPartyResources) Create(ctx context.Context, apiGroup, apiVersion, resource string, req, resp interface{}) error {
	url := t.c.urlFor(apiGroup, apiVersion, t.c.namespaceFor(ctx, true), resource, "")
	return t.c.create(ctx, jsonCodec, url, req, resp)
}

func (t *ThirdPartyResources) Get(ctx context.Context, apiGroup, apiVersion, resource, name string, resp interface{}) error {
	url := t.c.urlFor(apiGroup, apiVersion, t.c.namespaceFor(ctx, true), resource, name)
	return t.c.get(ctx, jsonCodec, url, resp)
}

func (t *ThirdPartyResources) Delete(ctx context.Context, apiGroup, apiVersion, resource, name string) error {
	url := t.c.urlFor(apiGroup, apiVersion, t.c.namespaceFor(ctx, true), resource, name)
	return t.c.delete(ctx, jsonCodec, url)
}

func (t *ThirdPartyResources) List(ctx context.Context, apiGroup, apiVersion, resource string, resp interface{}) error {
	url := t.c.urlFor(apiGroup, apiVersion, t.c.namespaceFor(ctx, true), resource, "")
	return t.c.get(ctx, jsonCodec, url, resp)
}

You then define request and response objects in wrapper methods that give your own code type checking.

from k8s.

ericchiang avatar ericchiang commented on May 16, 2024

Initial implementation https://godoc.org/github.com/ericchiang/k8s#Client.ThirdPartyResources

from k8s.

barakmich avatar barakmich commented on May 16, 2024

@ericchiang Very nice, can you add a line of example GoDoc for what apiGroup, apiVersion & resource mean (even if I can guess)?

from k8s.

ericchiang avatar ericchiang commented on May 16, 2024

πŸ‘ yeah

from k8s.

ericchiang avatar ericchiang commented on May 16, 2024

docs add here: https://godoc.org/github.com/ericchiang/k8s#ThirdPartyResources

from k8s.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.