Question: Trying to create a microservice within Go, I have a package network to take care of getting the bytes and converting to a particular request:

```
package network

type Request interface {
}

type RequestA struct {
a int
}

type RequestB struct {
b string
}

func GetRequestFromBytes(conn net.Conn) Request {
buf := make([]byte, 100)
_, _ := conn.Read(buf)
switch buf[0] {
case 0:
    // convert bytes into RequestA
    requestA = RequestAFromBytes(buf[1:])
    return requestA
case 1:
    requestB = RequestBFromBytes(buf[1:])
    return requestB
}}

```

Now in the main, I want to handle the request.

```
package main
import (
    "network"
)

(ra *RequestA) Handle() {
// handle here
}

(rb *RequestB) Handle() {
// handle
}

func main() {
    // get conn here
    req = GetRequestFromBytes(conn)
    req.Handle()
}

```

However, Golang does not allow RequestA/RequestB classes to be extended in the main package. Two solutions I found online were type aliasing/embedding, but in both it looks like we'll have to handle by finding the specific type of the request at runtime. This necessitates a switch/if statement in both network and main packages, which duplicates code in both.

The simplest solution would be to move the switch statement into package main, where we determine the type of the request and then handle it, but then package main would have to deal with raw bytes, which I'd like to avoid. The responsibility of finding the request type and sending it 'upwards' should rest with the network package.

Is there a simple idiomatic Go way to solve this?

Answer: 
`b = a` is an assignment by reference: it makes the variable `b` point at the same list that variable `a` is pointing to. So when you update the contents of that list on the next line, with `a[:] = ...` then both `a` and `b` are pointing to the updated list.

If the next line had been `a = [x**2 for x in a]` (instead of `a[:] = ...`) that would have created a new list `[1,9,25]` and assigned the variable `a` to point at it, leaving `b` still pointing at the original list.
When you do `b = a`, you simply creating a reference to the variable `a` and this reference is named `b`. A reference is just another name for the same object. You are not creating a copy of the variable `a`. Therefore, if you modify `b`, it modifies `a` as well and vice versa. 

However, if you do `b = a[:]`, you are creating a shallow copy of the variable `a` and assigning it to a new variable called `b`. Since `b` is a copy, modifying either one of them, won't change the other. 

That is precisely why you get two different answers when printing `b` at the end.