9 Matching Annotations
  1. Nov 2018
    1. Cobra既是一个用来创建强大的现代CLI命令行的golang库,也是一个生成程序应用和命令行文件的程序。下面是Cobra使用的一个演示:
    1. 在计算机科学领域,反射是指一类应用,它们能够自描述和自控制。也就是说,这类应用通过采用某种机制来实现对自己行为的描述(self-representation)和监测(examination),并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义
  2. Oct 2018
    1. Channels by default are blocking on sending and receiving values, so they will be waited on

      默认情况下,通道在发送和接收值时会阻塞,因此它们将被等待。

    1. Finally, we add the `xml:"sitemap"` syntax at the end for the parser to understand where it's looking when we go to unpack this with the encoding/xml package.

      最后,我们在末尾添加`xml:“sitemap”`语法,以便解析器在我们使用encoding / xml包解压缩它时的位置。

      type Sitemapindex struct {
          Locations []Location `xml:"sitemap"`
      }
      
    1. Personally, I would test both. If the gains are insignificant by using value receivers where possible and you are using pointer receivers, sure, use all pointer receivers. If you can make sizeable gains by using value receivers where possible, however, I would personally use them.

      就个人而言,我会测试两者。

      如果在可能的情况下使用值接收器并且您正在使用指针接收器,则增益无关紧要,请确保使用所有指针接收器。

      如果使用值接收器获取的收益微不足道,那么在可能的情况下,使用指针接收器,当然,所有地方都使用指针接收器

      但是,如果使用值接收器可以获得可观的收益,那么在可能的情况下,会亲自使用它们

    2. Now, we're modifying the struct itself via pointer. Now in the code we could do something like a_car.new_top_speed(500), and this would actually modify the object itself.

      现在,我们通过指针修改结构本身。现在在代码中我们可以做类似a_car.new_top_speed(500)的事情,这实际上会修改对象本身

    1. between the func keyword and the name of the function, we pass the variable and type. We use c, short for car, and then car, which is in association with the car struct. In this case, the method gets a copy of the object, so you cannot actually modify it here, you can only take actions or do something like coming up with a calculation

      func关键字和方法名之间,我们传递了变量和类型,

      我们使用c,汽车的简称,然后汽车,这是与汽车结构相关联。这样就把struct和method关联了起来

      在这种情况下,该方法获取对象的副本,因此您无法在此实际修改它,您只能执行操作或执行类似计算的操作 通过把struct和method关联了起来,使得方法获取到了对象的副本

      func (c car) kmh() float64 {
          return float64(c.gas_pedal) * (c.top_speed_kmh/usixteenbitmax)
      }
      
    2. In order to do this, we don't need to actually modify the a_car variable, so we can use a method on a value, called a value receiver:

      我们想把gas_pedal的值转化成某种实际的速度,为了做到这一点,我们不需要实际修改a_car变量,所以我们可以在值上使用一个方法,称为值 接收器

      func (c car) kmh() float64 {
          return float64(c.gas_pedal) * (c.top_speed_kmh/usixteenbitmax)
      }
      
    3. Methods that just access values are called value receivers and methods that can modify information are pointer receivers.

      只访问值的方法称为值接收器,只有获取值的需求时,用值接收器

      可以修改信息的方法是指针接收器,需要修改struct信息时,用指针接收器