New Vehicle Vin Recall Library

blov · · 391 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey, guys! Been a lurker on here for a bit and I wanted to start contributing to the Golang community. This is the first time I ever made a library for go so please go easy on me!</p> <p>The library allows you to search a vehicle vin number and get back some basic information like, make, model, and year. It also gives back any recalls that the car has had. It ties into the NHTSA API to give this information.</p> <p>Here is the link to the project: <a href="https://github.com/sooonmitch/GoVinRecall" rel="nofollow">https://github.com/sooonmitch/GoVinRecall</a></p> <p>I hope you guys like it and find things to do with it!</p> <hr/>**评论:**<br/><br/>barsonme: <pre><p>looks nice! good job. a couple of points:</p> <ul> <li><p>Error strings shouldn&#39;t end with punctuation, nor should they start with a capital unless the first word does.</p></li> <li><p>Try not to use naked returns.</p></li> <li><p>Lines 33-40 could just be </p> <pre><code>err = json.NewDecoder(r.Body).Scan(&amp;scan) return scan, err </code></pre></li> <li><p>Don&#39;t split your files up so much (I&#39;d put them all in one file).</p></li> <li><p>You&#39;re passing around http.DefaultClient for each lookup. Either use it without adding it to the <code>VinNumber</code> struct <em>or</em> allow the caller to add their own http.Client, preferably the latter. Similarly, <code>BaseURL</code> doesn&#39;t need to be a struct member.</p></li> <li><p><code>GetData</code> should probably be renamed to something like <code>Lookup</code>.</p></li> <li><p>The name <code>VinNum</code> (and friends) is redundant. Since VIN stands for Vehicle Identification Number, just use <code>vin</code> as the name of the function/method parameter and <code>VIN</code> as the struct name.</p></li> <li><p><code>VinScan.NumberOrRecalls</code> has a typo.</p></li> <li><p><code>VinScan.RefreshDate</code> could be a <code>time.Time</code></p></li> <li><p>Also, package names don&#39;t need to start with &#34;go&#34; :-)</p></li> </ul></pre>sooon_mitch: <pre><p>Thank you for the feedback :P I honestly did not think about how much this can teach me about the language. Tonight, I will change what you suggested. Thank you again!!!!:-)</p></pre>sooon_mitch: <pre><p>I changed almost everything, although I do have a question on how I could change RefreshDate to time.Time?</p></pre>maxice: <pre><p>Nice work!</p></pre>ZetaHunter: <pre><p>A custom json unmarshaller that converts string to <code>time.Time</code>.</p></pre>barsonme: <pre><p>well, if the date you get from the API is in the format the time package understands (I think it&#39;s RFC 3339) then you&#39;re good—just replace string with time.Time.</p> <p>If not, you&#39;ll need to write a custom json.Unmarshaler.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

391 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传