我正在尝试写一个短的,它将读取一个PNG文件,并交换一个通道与另一个(R,G,B)是可能的选择.
然而,我无法找到如何从image.At(x,y)返回的color.Color对象中提取整数.一旦我可以使用交换的通道构造新的RGBA颜色,使用image.Set(x,y,color)将其写回可能会更容易.
我现在在这里(你可以跳到最后一个循环):
package main
import (
"flag"
"fmt"
//"image"
"image/color"
"image/png"
"os"
)
type Choice struct {
value string
valid bool
}
func (c *Choice) validate() {
goodchoices := []string{"R", "G", "B"}
for _, v := range goodchoices {
if c.value == v {
c.valid = true
}
}
}
func main() {
var fname string
var c1 Choice
var c2 Choice
flag.StringVar(&c1.value, "c1", "", "The color channel to swap - R or G or B ")
flag.StringVar(&c2.value, "c2", …Run Code Online (Sandbox Code Playgroud) 我有一个数据源,它将创建大量我计划存储在 ElasticSearch 中的条目。源在 ElasticSearch 中为同一个文档创建了两个条目:
我需要在 ElasticSearch 中使用基于时间的索引,使用rollover index使用指向实际索引的别名。对于更新,我将使用更新 API来合并 init 和 finish。
问题:如果带有随机键的 init 文档不在当前索引中(但在一个已经翻转的旧索引中)是否会使用它的键成功执行更新它?如果没有,执行更新的最佳做法是什么?
我正处于了解Go中接口的早期阶段.我正在写一些逻辑模拟,并有类似下面的代码(我在这里大大简化):
请参阅我的问题的评论:
type LogicNode struct {
Input *bool
Output *bool
Operator string
Next Node
}
func (n *LogicNode) Run() {
// do some stuff here
n.Next.Run()
}
type Node interface {
Run()
}
func main() {
nodes := make([]Node, 1000)
for i := 0; i < 1000; i++ {
n := LogicNode{
//assign values etc.
}
nodes[i] = &n
}
for i, node := range nodes {
// I need to access LogicNode's Output pointer here, as a *bool.
// …Run Code Online (Sandbox Code Playgroud)