这个golang代码是做什么的? [英] What does this golang code do?

查看:95
本文介绍了这个golang代码是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读DigitalOcean的golang客户端。我注意到他们在 _ 变量中创建了一个* Op结构的实例。例如:
https://github.com/digitalocean/godo /blob/master/droplets.go#L32

  var _ DropletsService =& DropletsServiceOp {} 

为什么需要这一行?

解决方案

这行是编译时检查 * DropletsServiceOp 满足 DropletsService 接口。



该行对程序的执行没有影响。 b

I was reading DigitalOcean's golang client. I noticed that they create an instance of their *Op struct in a _ variable. Example: https://github.com/digitalocean/godo/blob/master/droplets.go#L32

var _ DropletsService = &DropletsServiceOp{}

Why is this line needed?

解决方案

This line is a compile time check that *DropletsServiceOp satisfies the DropletsService interface.

The line has no effect on the execution of the program.

这篇关于这个golang代码是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆