小编jub*_*0bs的帖子

如何 git delete 一个分支和一个同名的标签,名称中都带有斜杠?

我有一个 git 分支和一个 git 标签,它们在本地和远程都具有相同的名称和多个斜杠。

我想写一个bash脚本调用git命令删除本地分支和本地标签,然后是远程分支和远程标签。

对于此示例,假设分支/标签名称为: production/2020/12/10

该分支/标签名称是一个假设,可以找到适用于更好命名的分支/标签的解决方案。

任何帮助将不胜感激。

git git-tag git-branch

0
推荐指数
1
解决办法
154
查看次数

如何查明“不允许导入周期”的问题?

如何分析哪个源文件导致“不允许导入循环”问题?错误消息不够清楚,无法让我解决问题:

package command-line-arguments
    imports app.exap/i8/internal
    imports app.exap/i8/internal/data/retrieves
    imports app.exap/i8/internal/integration/datastore
    imports app.exap/i8/internal/objects/modules
    imports app.exap/i8/internal/data
    imports app.exap/i8/internal/integration/datastore: import cycle not allowed
package command-line-arguments
    imports app.exap/i8/internal
    imports app.exap/i8/internal/data/retrieves
    imports app.exap/i8/internal/integration/datastore
    imports app.exap/i8/internal/objects/modules
    imports app.exap/i8/internal/data
    imports app.exap/i8/internal/objects/modules: import cycle not allowed
Run Code Online (Sandbox Code Playgroud)

circular-dependency go

0
推荐指数
1
解决办法
95
查看次数

os.Stdout 和 syscall.Stdout 有什么区别?

我一直在尝试使用 ForkExec() 但我无法完成这项工作,syscall.Stdout 和 os.Stdout 之间有区别吗?

这是我尝试运行的代码的一个小例子。

command := "/usr/bin/echo"
args := []string{"Hello there."}
attr := new(syscall.ProcAttr)
attr.Env = os.Environ()
attr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)}
pid , err := syscall.ForkExec(command, args, attr)
if err != nil {
    log.Fatal(err)
}
fmt.Println(pid)
Run Code Online (Sandbox Code Playgroud)

输出未显示在屏幕上。

非常感谢您的帮助。

stdout system-calls go

0
推荐指数
1
解决办法
54
查看次数

切片副本改变原始切片

有人可以帮助解释 Golang 内部为什么这段代码会改变原始数组a吗?

func main() {
    a := []int{1,2,3,4}
    b := a
    b = append(b[0:1], b[2:]...)
    fmt.Println(b)
    fmt.Println(a)
}
Run Code Online (Sandbox Code Playgroud)

输出:

[1 3 4]
[1 3 4 4]
Run Code Online (Sandbox Code Playgroud)

我以为b := a会按值传递。提前致谢。

go slice

0
推荐指数
1
解决办法
733
查看次数

尽管有测试功能,为什么我还是“没有测试要运行”?

新手来这里,我写了一个简单的 main_test.go 文件来运行 main.go 的一些测试用例,当我运行go test它时说 testing:warning: no tests to run PASS ok Solution 0.878s

我的 main.go:

package main

func normalizePhoneNum(phoneNumber string) string {
    return ""
}

func main() {

}
Run Code Online (Sandbox Code Playgroud)

main_test.go:

package main

import (
    "testing"
)

func testNormalizePhoneNum(t *testing.T) {
    testCase := []struct {
        input  string
        output string
    }{
        {"1234567890", "1234567890"},
        {"123 456 7891", "123 456 7891"},
        {"(123) 456 7892", "(123) 456 7892"},
        {"(123) 456-7893", "(123) 456-7893"},
        {"123-456-7894", "123-456-7894"},
        {"123-456-7890", "123-456-7890"},
        {"1234567892", "1234567892"},
        {"(123)456-7892", "(123)456-7892"},
    } …
Run Code Online (Sandbox Code Playgroud)

testing go

0
推荐指数
1
解决办法
79
查看次数

已部署的应用程序立即自行关闭

我有一个 Golang rest API 应用程序。我将它 Docker 化并部署到 Kubernetes。它在我的本地工作正常。

但是在 Kubernetes 中,应用程序会自行关闭,然后 pod 会重新启动。

我不明白为什么会发生这种情况。它不打印任何内容、任何日志或任何失败。

import ( 
" github.com/gorilla/mux"
"net/http"
"log"

)   
func main() {
    controller := controllers.Controllers{}
    router := mux.NewRouter()
    router.HandleFunc("/customer", controller.GetCustomer()).Methods("GET")
    router.HandleFunc("/customer", controller.InsertCustomer()).Methods("POST")
    router.HandleFunc("/healthcheck", controller.HealthCheck())

    addr := ":" + os.Getenv("PORT")
    srv := &http.Server{Addr: addr, Handler: router}

    go func() {
        if err := srv.ListenAndServe(); err != nil {
            log.Fatalf("listenAndServe failed: %v", err)
        }
    }()
    println("reached here")
}
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,当我查看日志时,我可以看到“到达此处”行。因此,出于某种原因,它会自行关闭。我检查了 env 变量,它也是正确的。我怀疑listenAndServe,但找不到合理的答案。为什么会是这个原因?

rest http go gorilla kubernetes

0
推荐指数
1
解决办法
54
查看次数

是否存在 1 <= x <= 255 范围内的 Int 类型?

我想创建以下声明:

data Color = B | W deriving Read

type Cell = (Color, Int) where 1 <= Int <= 255
Run Code Online (Sandbox Code Playgroud)

这个问题有什么解决办法吗?该类型实际上接受任何类型,Int但超出该范围的类型不应编译。

haskell

0
推荐指数
1
解决办法
156
查看次数

为什么这样的递归Haskell函数不起作用?

这是代码:

rep' :: Int -> a -> [a]
rep' 0 x = []
rep' n x = x:rep'(n-1, x)
Run Code Online (Sandbox Code Playgroud)

我试着像这样重写它:

rep' :: Int -> a -> [a]
rep' 0 x = []
rep' n x = x:(rep' n-1 x)
Run Code Online (Sandbox Code Playgroud)

但它也不起作用.

baby.hs:3:15-20: Couldn't match expected type ‘[a]’ with actual type ‘a0 -> [a0]’ …
    Relevant bindings include
      x :: a (bound at /Users/hanfeisun/Workspace/haskell/baby.hs:3:8)
      rep' :: Int -> a -> [a]
        (bound at /Users/hanfeisun/Workspace/haskell/baby.hs:2:1)
    Probable cause: ‘rep'’ is applied to too few …
Run Code Online (Sandbox Code Playgroud)

haskell

-1
推荐指数
2
解决办法
104
查看次数

获取并在Haskell中放入一个字符串会引发错误

我发现了以下Haskell代码,但我很困惑:

main = putStrLn "Enter 1st String:"  
  >> getLine
  >>= \a -> read a
Run Code Online (Sandbox Code Playgroud)
  1. 两个"大于"符号(>>)的含义是什么?一个新的声明?

  2. 两个"大于"符号后面跟一个等号(>>=)是什么意思?

此Haskell代码抛出以下错误:

a.hs:3:13:
No instance for (Read (IO t0)) arising from a use of ‘read’
In the expression: read a
In the second argument of ‘(>>=)’, namely ‘\ a -> read a’
In the expression:
  putStrLn "Enter 1st String:" >> getLine >>= \ a -> read a
Run Code Online (Sandbox Code Playgroud)

haskell ghc

-2
推荐指数
1
解决办法
80
查看次数

为什么竞态检测器在这里报告竞态条件?

我正在使用 Go 竞争检测(-race 参数),它检测到一些我认为不应该报告的竞争条件问题。我创建了这个示例代码来解释我的发现。请不要对此示例的目标发表评论,因为它除了解释问题之外没有其他目标。

这段代码:

var count int

func main() {
    go update()
    for {
        fmt.Println(count)
        time.Sleep(time.Second)
    }
}

func update() {
    for {
        time.Sleep(time.Second)
        count++
    }
}
Run Code Online (Sandbox Code Playgroud)

报告有竞争条件。

虽然这段代码:

var count int
var mutex sync.RWMutex

func main() {
    go update()
    for {
        mutex.RLock()
        fmt.Println(count)
        mutex.RUnlock()
        time.Sleep(time.Second)
    }
}

func update(){
    for {
        time.Sleep(time.Second)
        mutex.Lock()
        count++
        mutex.Unlock()
    }
}
Run Code Online (Sandbox Code Playgroud)

没有报告任何竞争条件问题。

我的问题是为什么?第一个代码中没有错误。main 函数正在读取另一个 go 例程正在更新的变量。这里没有潜在的隐藏错误。第二个代码互斥锁不提供任何不同的行为。

我哪里错了?

synchronization mutex global-variables go race-condition

-2
推荐指数
1
解决办法
104
查看次数

如何在Haskell中返回一个元组

type Record=([Char],[Char],[Char],[Char],[Char])

createAccount::IO()->Record
createAccount=do
    putStrLn "Enter First Name"
    fname<-getLine
    putStrLn "Enter Last Name"
    lname<-getLine
    putStrLn "Enter State"
    state<-getLine
    putStrLn "Enter City"
    city<-getLine
    putStrLn "Enter House No."
    hnum<-getLine
    let hnumInt = read hnum :: Integer
    putStrLn "Enter Contact"
    contact<-getLine
    return (fname,lname,state,city,contact)
Run Code Online (Sandbox Code Playgroud)

haskell tuples

-3
推荐指数
1
解决办法
229
查看次数

检查未知接口{}是否为空

您好,我想知道如果 aninterface{}为空,我将如何在 Go 中进行验证。我尝试过reflect.TypeOf(v) == nil,但它总是返回false

    var h  Bar
    var t  Foo
    pointers := make([]interface{}, 0)
    pointers = append(pointers, &h)
    pointers = append(pointers, &t)

func test(byteValue []byte, data []interface{}) {
    for _, v := range  data {
        fmt.Println(reflect.TypeOf(v) == nil)
        if err := lib.Unmarshal(byteValue, v); err == nil {
            fmt.Println(err)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

reflection go

-3
推荐指数
1
解决办法
733
查看次数

是否有"= +"运算符这样的东西?

我想知道为什么+=有效但=+无效.假设我有这样的代码:

string strOne = "World!";
strOne =+ "Hello ";//strOne = "Hello " + strOne; not valid
//Error: Operator '+' cannot be applied to operand of type 'string'
//Intended Output: Hello World!

string strTwo = "Hello ";
strTwo += "World!";//strTwo = strTwo + "World!"; valid
//Output: Hello World!
Run Code Online (Sandbox Code Playgroud)

我也不确定是否strOne =+ "Hello ";相同strOne = "Hello " + strOne;.是否有任何关于为什么=+无效或无法在语法上正确的规则?

c# syntax-error

-6
推荐指数
1
解决办法
2090
查看次数