Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

High-level thoughts. #40

Closed
Closed
@flowchartsman

Description

@flowchartsman

This repo could use some reorganization that would make it more ergonomic to use:

  • pulsar-admin-go is an unimportable identifier, whereas admin is non-specific.
    • consider renaming the root module to pulsaradmin, and move the contents of pkg/admin into the repository root
  • in general, this package doesn't really need any subpackages at all, with the exception of pkg/rest (and maybe pkg/auth) which should probably be in /internal unless there's a compelling reason to expose them beyond auth configuration, which can live in the project root.. Changes like Error improvements #39 would be the way to expose these. The reorganizations in Optimize project layout #3 Decouple config and auth package #4 feel a bit premature, especially since most users will require at least some kind of auth, so why bother making them import another package?
    • move everything from /pkg into project root or /internal
    • expose necessary types for errors/auth/etc in the root module
  • You could even eliminate some of the more confusing overlapping configuration values (len(ClientID)>0 bit me in particular) by simply placing
    • placingAuthProvider directly into the config struct and
    • moving the auth.NewAuth* helpers to the top level and shortening their names

Refs on /internal:

Overall, fewer imports make it easier to be productive with your client without needing to jump around docs and code.

Consider the difference between

import (
	pulsaradmin "github.com/streamnative/pulsar-admin-go"
	pulsarauth "github.com/streamnative/pulsar-admin-go/pkg/admin/auth"
	pulsaradmincfg "github.com/streamnative/pulsar-admin-go/pkg/admin/config"
	pulsarutils "github.com/streamnative/pulsar-admin-go/pkg/utils"
)

func main() {
	paClient, err := pulsaradmin.NewClient(&pulsaradmin.Config{
		PulsarAPIVersion:              pulsaradmincfg.V3,
		WebServiceURL:                 webServiceURL,
		BKWebServiceURL:               custerURL,
		AuthPlugin:                    pulsarauth.TokenPluginName,
		AuthParams:                    tokenData,
		TLSTrustCertsFilePath:         `/etc/ssl/certs`,
		TLSEnableHostnameVerification: true,
	})
	// err handle
	err := paClient.Functions().CreateWithURL(&pulsarutils.FunctionConfig{
		Output:     funcResults,
		LogTopic:   funcLog,
		Tenant:     funcTenant,
		Namespace:  funcNamespace,
		Name:       funcName,
		Inputs:     []string{funcInput},
		Runtime:    "GO",
	}, funcURL)
	// err handle
}

and

import (
	pulsaradmin "github.com/streamnative/pulsar-admin-go"
)

func main() {
	paClient, err := pulsaradmin.NewClient(&pulsaradmin.ClientConfig{
		APIVersion:    pulsaradmin.APIV3,
		WebServiceURL: webServiceURL,
		BKURL:         clusterURL,
		AuthProvider:  pulsarAdmin.AuthToken(tokenData),
		TLSConfig: &pulsarAdmin.TLSConfig{
			TrustCertsPath: `/etc/ssl/certs`,
			HostnameVerify: true,
		},
	})
	// err handle
	err := paClient.Functions().CreateFuncWithURL(funcURL, &pulsaradmin.FunctionConfig{
		Output:     funcResults,
		LogTopic:   funcLog,
		Tenant:     funcTenant,
		Namespace:  funcNamespace,
		Name:       funcName,
		Inputs:     []string{funcInput},
		Runtime:    "GO",
	})
	// err handle
}

Which only requires a single package and is very autocomplete-friendly.

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