我有一个 Github 组织,并尝试将容器注册表从 迁移docker hub到GitHub Packages. 通过使用 Github Workflows,这是我用来将 docker 推送到的 yaml GitHub Packages:
name: ghcr_test
on:
push:
branches:
- dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to GitHub Packages
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
Run Code Online (Sandbox Code Playgroud)
GitHub 建议在操作工作流程中使用 GITHUB_TOKEN,我已经仔细检查了它在我的组织设置中是否具有读写权限,但他们给了我这个错误
Error: buildx …Run Code Online (Sandbox Code Playgroud) 尝试联合向量时出现此错误
error: Vectors of unions are not yet supported in all the specified
programming languages.
Run Code Online (Sandbox Code Playgroud)
显然,flatbuffers不支持联合向量。所以我需要另一种数据类型来解决我的问题。这是我的情况:
使用模型实体组件系统(ECS),我有3个实体和3个组件,这是结构
EntityA EntityB EntityC
component1 component1 component3
component3 component2
Run Code Online (Sandbox Code Playgroud)
如果我可以使用联合向量,则架构如下所示
union Components { Component1, Component2, Component3 }
table Update {
component:[Components];
}
Run Code Online (Sandbox Code Playgroud)
其中Component [N]是表。实际上我有一个没有联合向量的解决方案
table Update {
component1:[Component1];
component2:[Component2];
component3:[Component3];
}
Run Code Online (Sandbox Code Playgroud)
但是,当组件列表增加时,它变得难以管理。
抱歉,我正在使用ECS,这实际上是用于游戏开发。但这与游戏无关,所以我认为这是提出此类问题的正确位置。
没有联合向量并且如何解决上述问题,如何解决呢?
我想在go(lang)中创建游戏循环,所以我尝试了这个:
package main
import (
"fmt"
// "runtime"
"sync"
"time"
)
var v = 0
var wg sync.WaitGroup
var sec = 5
func main() {
wg.Add(1)
gameLoop()
wg.Wait()
}
func gameLoop() {
time.AfterFunc(16*time.Millisecond, gameLoop)
v++
fmt.Println(v)
if v == sec*60 {
// fmt.Println("Goroutines: ", runtime.NumGoroutine())
panic("err")
wg.Done()
}
}
Run Code Online (Sandbox Code Playgroud)
该程序以62.5Hz运行(16*time.Millisecond),var sec用于wg.Done()在5秒后调用并导致var v打印300次.
调用这样panic("err")的结果:
panic: err
goroutine 314 [running]:
panic(0x493c60, 0xc420094370)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
main.gameLoop()
/home/billyzaelani/Desktop/main.go:26 +0x11f
created by time.goFunc
/usr/local/go/src/time/sleep.go:154 +0x44
exit status …Run Code Online (Sandbox Code Playgroud) 考虑我有一些字符串路径:
paths := []string{"/path0", "/path1", "/path2" /*... "/path-n"*/ }
// where n is the last path
Run Code Online (Sandbox Code Playgroud)
使用包net/http,我想使用for带有range子句的循环注册此路径的处理程序.这就是我这样做的方式:
for _, path := range paths {
http.HandleFunc(path, handler)
}
// in this case every handler is print the path to the console or to the browser
Run Code Online (Sandbox Code Playgroud)
但我最终得到了相同的输出,这是切片的最后一个元素,所以当我去/path1,输出是/path-n.与其他元素的行为相同,始终打印/path-n.
但如果我用这个:
for _, path := range paths {
http.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, path)
})
}
Run Code Online (Sandbox Code Playgroud)
输出是正确的.
发生了什么事,我错过了什么吗?我需要for通过切片路径或地图给出的循环注册,所以我不能做第二个代码.
你能给我替代完成这项任务吗?