这是合理且惯用的GoLang循环移位实现吗?

Can anyone comment on whether this is a reasonable and idiomatic way of implementing circular shift of integer arrays in Go? (I deliberately chose not to use bitwise operations.)

How could it be improved?

package main

import "fmt"

func main() {
    a := []int{1,2,3,4,5,6,7,8,9,10}
    fmt.Println(a)
    rotateR(a, 5)
    fmt.Println(a)
    rotateL(a, 5)
    fmt.Println(a)
}

func rotateL(a []int, i int) {
    for count := 1; count <= i; count++ {
        tmp := a[0]
        for n := 1;n < len(a);n++ {
            a[n-1] = a[n]
        }
        a[len(a)-1] = tmp
    }
}

func rotateR(a []int, i int) {
    for count := 1; count <= i; count++ {
        tmp := a[len(a)-1]
        for n := len(a)-2;n >=0 ;n-- {
            a[n+1] = a[n]
        }
        a[0] = tmp
    }
}

Your code is fine for in-place modification.

Don't clearly understand what you mean by bitwise operations. Maybe this

package main

    import "fmt"

    func main() {
        a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        fmt.Println(a)
        rotateR(&a, 4)
        fmt.Println(a)
        rotateL(&a, 4)
        fmt.Println(a)
    }

    func rotateL(a *[]int, i int) {
        x, b := (*a)[:i], (*a)[i:]
        *a = append(b, x...)
    }

    func rotateR(a *[]int, i int) {
        x, b := (*a)[:(len(*a)-i)], (*a)[(len(*a)-i):]
        *a = append(b, x...)
    }

Code works https://play.golang.org/p/0VtiRFQVl7

It's called reslicing in Go vocabulary. Tradeoff is coping and looping in your snippet vs dynamic allocation in this. It's your choice, but in case of shifting 10000 elements array by one position reslicing looks much cheaper.

Rotating the slice one position at a time, and repeating to get the total desired rotation means it will take time proportional to rotation distance × length of slice. By moving each element directly into its final position you can do this in time proportional to just the length of the slice.

The code for this is a little more tricky than you have, and you’ll need a GCD function to determine how many times to go through the slice:

func gcd(a, b int) int {
    for b != 0 {
        a, b = b, a % b
    }

    return a
}

func rotateL(a []int, i int) {

    // Ensure the shift amount is less than the length of the array,
    // and that it is positive.
    i = i % len(a)
    if i < 0 {
        i += len(a)
    }

    for c := 0; c < gcd(i, len(a)); c++ {

        t := a[c]

        j := c

        for {
            k := j + i
            // loop around if we go past the end of the slice
            if k >= len(a) {
                k -= len(a)
            }
            // end when we get to where we started
            if k == c {
                break
            }
            // move the element directly into its final position
            a[j] = a[k]
            j = k
        }

        a[j] = t
    }
}

Rotating a slice of size l right by p positions is equivalent to rotating it left by lp positions, so you can simplify your rotateR function by using rotateL:

func rotateR(a []int, i int) {
    rotateL(a, len(a) - i)
}

I like Uvelichitel solution but if you would like modular arithmetic which would be O(n) complexity

package main
func main(){
   s := []string{"1", "2", "3"}
   rot := 5
   fmt.Println("Before RotL", s)
   fmt.Println("After RotL", rotL(rot, s))
   fmt.Println("Before RotR", s)
   fmt.Println("After RotR", rotR(rot,s))

}
func rotL(m int, arr []string) []string{
     newArr := make([]string, len(arr))

     for i, k := range arr{
         newPos := (((i - m) % len(arr)) + len(arr)) % len(arr)
         newArr[newPos] = k
     }

     return newArr
}

func rotR(m int, arr []string) []string{

     newArr := make([]string, len(arr))

     for i, k := range arr{
         newPos := (i + m) % len(arr)
         newArr[newPos] = k
      }
      return newArr
}