Giter Site home page Giter Site logo

go-packages's People

Contributors

andruwm avatar cdrayn avatar jon-lundy-caring avatar miraclecaring avatar mykelswitzer avatar sarabm avatar shyhshyanhsu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-packages's Issues

[uuid] Parse and ParseUUIDs should return an error for invalid entries

Background

Parse and ParseUUIDs currently return an empty UUID when given an empty string. I think this a carryover from a SQL database-specific implementation. I feel it is unexpected behavior outside of that context.

Proposed Solution

Parse and ParseUUIDs should behave like the underlying google counterpart and error when an empty string is passed in. Additionally, we may want to rename these methods to ParseString and ParseStrings in the event we add other methods like ParseBytes. This could help prevent breaking change by deprecating the old methods. Two new methods should be added (potentially) to contain the previous behavior. These could be called ParseStringOrEmpty and ParseStringsOrEmpty.

[uuid] Create a better way to interface with gofrs uuid

Background

https://pkg.go.dev/github.com/gofrs/uuid?utm_source=godoc

gofrs is used by the the event store DB Go SDK. Currently, there isn't a clean way to convert between the two types, because we have wrapped the underlying [16]byte byte array in a struct. Below is what I have currently been doing.

ID, err := gofrs.FromString(m.EventID().String())

Potential Solutions

  1. Cast the underlying byte array to the gofrs uuid then return that. Implementation would be something like follows
func (uuid UUID) GofrsUUID() gofrs.UUID
  1. Return the underlying byte array through a method so that gofrs can parse it. (this way is a little more verbose but it is cleaner
func (uuid UUID) Bytes() []byte

id, err := gofrs.FromBytes(uuid.New())

Other considerations

We will likely need a way to go gofrs uuid -> caring uuid

Need nullValue method to be added to uuid pkg

if an uuid is empty, need to insert a null value to mysql database instead of "00000000-0000-0000-0000-000000000000"

use case:

result, err = stmt.ExecContext(ctx, input.ID, input.Name, input.StatusID, nullValueUUID(input.CustomerID), nullValueUUID(input.OrgID))
	if err != nil {
		return errors.Wrap(err, errMsg())
	}

// nullUUID checks if an uuid is empty and returns a sql null string.
func nullValueUUID(id uuid.UUID) sql.NullString {
	if id == uuid.Nil {
		return sql.NullString{String: id.String(), Valid: false}
	} else {
		return sql.NullString{String: id.String(), Valid: true}
	}
}

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.