如何在一行代码中将buf分成两个切片?

Split a buf into two slices.

One is

buf[:n]

other is

buf[n:].

n maybe larger than len(buf). Finish it just using one line code .

Is there any grace code ?

This is not elegant, nor practical, but the evaluation is on one line...

package main

import (
    "fmt"
)

func main() {
    buf := "abcdefg"
    n := 8

    // fugly one-liner
    a, b, err := func() (string, string, error) {if n > len(buf) {return "", "", fmt.Errorf("out of bounds")} else {return buf[:n], buf[n:], nil}}()

    if err != nil {
        fmt.Println(err.Error())
    } else {
        fmt.Print(a + ":" + b)
    }
}