Skip to content

Make the API more idiomatic as a Go library #17

@kirsle

Description

@kirsle

This is a blanket ticket for going through the codebase and doing general cleanup and API fixes to make the code more idiomatic from a Go point of view.

Examples:

  • More functions should return error objects to communicate failure conditions rather than relying on "magic" return values like empty strings.

    • e.g. func ClearUservars(username string) error could return an error when the user had no vars to clear.
    • e.g. func CurrentUser() (string, error) where it gives an error when called outside of an object macro context, rather than what it currently does by returning an empty string -- this isn't idiomatic Go.
  • User variable getter functions should be refactored to make more sense for "API context" vs. "internal use w/ <get>"

    • The public API functions like GetUservar() should follow Go idioms and return "", error in case of errors rather than "undefined", error
    • The internal use of the functions for the <get> types of tags would handle the mapping of "" to "undefined" for their own use.
  • Find a way to make the constructor config object easier to get and use. It's stupid to need to import aichaos/rivescript-go/config to get the config.Config{} type for initializing RiveScript. The config type should be available directly from the parent package.

    This might require refactoring to make the parent package include more logic for config handling rather than just proxying all methods through to the /src versions, but that's probably a good thing anyway. The /src package is private use only and I already spelled out in its docs that its API can be changed at any time without notice.

    bot := rivescript.New(rivescript.BasicConfig())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions