{"action":"created","issue":{"url":"https://api.github.com/repos/ipfs/go-cid/issues/53","repository_url":"https://api.github.com/repos/ipfs/go-cid","labels_url":"https://api.github.com/repos/ipfs/go-cid/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/ipfs/go-cid/issues/53/comments","events_url":"https://api.github.com/repos/ipfs/go-cid/issues/53/events","html_url":"https://github.com/ipfs/go-cid/pull/53","id":336837713,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk4MTk3MDgw","number":53,"title":"Create new Format interface for creating CIDs.","user":{"login":"kevina","id":1271492,"node_id":"MDQ6VXNlcjEyNzE0OTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1271492?v=4","gravatar_id":"","url":"https://api.github.com/users/kevina","html_url":"https://github.com/kevina","followers_url":"https://api.github.com/users/kevina/followers","following_url":"https://api.github.com/users/kevina/following{/other_user}","gists_url":"https://api.github.com/users/kevina/gists{/gist_id}","starred_url":"https://api.github.com/users/kevina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevina/subscriptions","organizations_url":"https://api.github.com/users/kevina/orgs","repos_url":"https://api.github.com/users/kevina/repos","events_url":"https://api.github.com/users/kevina/events{/privacy}","received_events_url":"https://api.github.com/users/kevina/received_events","type":"User","site_admin":false},"labels":[{"id":483558964,"node_id":"MDU6TGFiZWw0ODM1NTg5NjQ=","url":"https://api.github.com/repos/ipfs/go-cid/labels/in%20progress","name":"in progress","color":"ededed","default":false}],"state":"open","locked":false,"assignee":{"login":"kevina","id":1271492,"node_id":"MDQ6VXNlcjEyNzE0OTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1271492?v=4","gravatar_id":"","url":"https://api.github.com/users/kevina","html_url":"https://github.com/kevina","followers_url":"https://api.github.com/users/kevina/followers","following_url":"https://api.github.com/users/kevina/following{/other_user}","gists_url":"https://api.github.com/users/kevina/gists{/gist_id}","starred_url":"https://api.github.com/users/kevina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevina/subscriptions","organizations_url":"https://api.github.com/users/kevina/orgs","repos_url":"https://api.github.com/users/kevina/repos","events_url":"https://api.github.com/users/kevina/events{/privacy}","received_events_url":"https://api.github.com/users/kevina/received_events","type":"User","site_admin":false},"assignees":[{"login":"kevina","id":1271492,"node_id":"MDQ6VXNlcjEyNzE0OTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1271492?v=4","gravatar_id":"","url":"https://api.github.com/users/kevina","html_url":"https://github.com/kevina","followers_url":"https://api.github.com/users/kevina/followers","following_url":"https://api.github.com/users/kevina/following{/other_user}","gists_url":"https://api.github.com/users/kevina/gists{/gist_id}","starred_url":"https://api.github.com/users/kevina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevina/subscriptions","organizations_url":"https://api.github.com/users/kevina/orgs","repos_url":"https://api.github.com/users/kevina/repos","events_url":"https://api.github.com/users/kevina/events{/privacy}","received_events_url":"https://api.github.com/users/kevina/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-06-29T02:04:01Z","updated_at":"2018-07-06T19:08:22Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/ipfs/go-cid/pulls/53","html_url":"https://github.com/ipfs/go-cid/pull/53","diff_url":"https://github.com/ipfs/go-cid/pull/53.diff","patch_url":"https://github.com/ipfs/go-cid/pull/53.patch"},"body":"This is my proposed alternative to #52 \r\n\r\nMy making `Format` an interface we can easily extend it to provide additional functionality outside of the `go-cid` package.  In addition the current `Prefix` implemented the `Format` interface so to take advantage of the added functional all we need to is is change the signature of functions that take a `cid.Prefix` to `cid.Format`.\r\n\r\nI specifically did not add support for automatically creating identity hashes as that can be added later, and possible outside of `go-cid`.  The code could look something like:\r\n```go\r\n  struct FormatWithInlining {Base Format, Limit int}\r\n\r\n  func WithInlinling(base Format) {\r\n    return FormatWithInlining{Base: base, Limit: DefaultInlineLimit}\r\n  }\r\n\r\n  func (f FormatWithInlining) Sum(data []byte) (*Cid, error) {\r\n    if len(data) <= f.Limit {/* use id hash*/}\r\n    else {return f.Base.Sum(data)}\r\n  }\r\n```\r\n\r\nAt some point in the future we can remove NewPrefixV0, NewPrefixV1 and Prefix.Sum.  We should also consider making the MhLength field an unsigned integer to disallow -1 as a value.\r\n\r\nSome additional nodes:  I find the field names `MhType` and `MhLength` crypt and think `HashFun` and `HashLen` are better and easier to understand names so I used those in this structure.  If we are dead set on `MhType` and `MhLength` I can change it back."},"comment":{"url":"https://api.github.com/repos/ipfs/go-cid/issues/comments/403121825","html_url":"https://github.com/ipfs/go-cid/pull/53#issuecomment-403121825","issue_url":"https://api.github.com/repos/ipfs/go-cid/issues/53","id":403121825,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzEyMTgyNQ==","user":{"login":"Mr0grog","id":74178,"node_id":"MDQ6VXNlcjc0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/74178?v=4","gravatar_id":"","url":"https://api.github.com/users/Mr0grog","html_url":"https://github.com/Mr0grog","followers_url":"https://api.github.com/users/Mr0grog/followers","following_url":"https://api.github.com/users/Mr0grog/following{/other_user}","gists_url":"https://api.github.com/users/Mr0grog/gists{/gist_id}","starred_url":"https://api.github.com/users/Mr0grog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mr0grog/subscriptions","organizations_url":"https://api.github.com/users/Mr0grog/orgs","repos_url":"https://api.github.com/users/Mr0grog/repos","events_url":"https://api.github.com/users/Mr0grog/events{/privacy}","received_events_url":"https://api.github.com/users/Mr0grog/received_events","type":"User","site_admin":false},"created_at":"2018-07-06T19:08:22Z","updated_at":"2018-07-06T19:08:22Z","author_association":"NONE","body":">  We currently use Prefix for both but that leads to some odd cases\r\n\r\nAh, ok. Is this mainly so code that deals with it never has to look up the right hash length the way `Format.Sum()` does? I guess I was looking at the code like:\r\n\r\n```go\r\nmetadata := cid.NewPrefixV1(cid.DagCBOR, mh.SHA2_256)\r\n// or if Prefix-using functions could handle default length lookups when 0, or there was an accessor for hash length:\r\n// metadata := cid.Prefix{Version: 1, Codec: cid.DagCBOR, MhType: mh.SHA2_256}\r\nid := metadata.Sum(bytesOfContent)\r\n\r\n// vs.\r\n\r\nmetadata := cid.FormatV1{Codec: cid.DagCBOR, HashFun: mh.SHA2_256}\r\nid := metadta.Sum(bytesOfContent)\r\n```\r\n\r\n…which didn’t feel like it was getting us much,  but I also don’t know what \"additional functionality\" we are heading towards. If there’s a lot on the table, I can see how all the empty/optional fields a struct affords that Go’s lack of optional arguments doesn’t would be useful.\r\n\r\nSince these two structs are so similar, this definitely feels like it needs some documentation pointing the way (both text in the package overview saying you should use the `Format` struct to create a CID for some bytes vs. `NewCidVx()` if you already have a hash and some docs in `format.go`), and maybe an example in the test file. I don’t think I’ll be alone in not totally understanding this.\r\n\r\n**Anyway, on the original point:** all that does make me feel like having the names match is pretty valuable in this case (unless we might be comfortable changing `Prefix` to use different field names). `MhType` and `HashFun` would be representing the exact same thing and for pretty much the same purpose in both places. That’s a good reason to keep the names consistent, even if I’m not a big fan of the names themselves :)"}}
{"actor":{"display_login":"Mr0grog"}}