Golang元帅和Unmarshal错误

I am new to golang while creating a blockchain smart contract function below

func (s *SmartContract)  changeStatus(APIstub shim.ChaincodeStubInterface,args[]string) sc.Response{
    if len(args) != 2 {
        return shim.Error("Incorrect number of arguments. Expecting 2")
    }
    licenceAsBytes, _ := APIstub.GetState(args[0]);
    var result Licence
    json.Unmarshal([]byte(licenceAsBytes), result)
    result.Status := args[1]
    licenceAsBytes, _ := json.Marshal(result)
    APIstub.PutState(args[0], licenceAsBytes);

    return shim.Success(nil)

} 

When I'm calling this function, I am getting the following error:

Error: could not assemble transaction, err proposal response was not successful, error code 500, msg error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 2 "# github.com/fabcar/go chaincode/input/src/github.com/fabcar/go/fabcar.go:110:8: non-name result.Status on left side of := chaincode/input/src/github.com/fabcar/go/fabcar.go:111:20: no new variables on left side of := "

As @icza pointed out, you cannot use shorthand notation twice within a single block, like this:

licenceAsBytes, _ := APIstub.GetState(args[0]);
...
licenceAsBytes, _ := json.Marshal(result)

The second should read:

licenceAsBytes, _ = json.Marshal(result)

Similarly, the following is invalid:

result.Status := args[1]

as it does not define a new variable (it assigns a value to a struct field).

While not an error, for anything, that might go into production, you probably do not want to ignore errors silently (as your current code snippet does, 3x).

a, b := 5, 6 a and b is declared and initialized. If again we use them in a statement like a, _ := some_func(), then error will occur and it will say no new var in left side of the statement. If at least one of them is not declared previously then it will execute without such error.

So, in your case, change this

result.Status := args[1]
licenceAsBytes, _ := json.Marshal(result)

to

result.Status = args[1]
licenceAsBytes, _ = json.Marshal(result)