go-pus/errors.go
Randy Reddig 25a249fbd5 feat: build without libopusfile using go build tag
This patch introduces a new build tag `nolibopusfile` that conditionally
compiles out the code that imports `libopusfile`. This enables a static
binary build on Alpine Linux, which doesn’t have a static `libopusfile`.

Tests still work:

```sh
go test -tags nolibopusfile ./...
go test ./...
```

We could also have moved all libopusfile related code (i.e. Stream) into
a separate sub-package, but that would break backwards compatibility.
This feature is too unpopular to justify introducing a new major
version.

See also: https://github.com/hraban/opus/pull/24
2020-07-10 13:54:23 +01:00

37 lines
824 B
Go

// Copyright © Go Opus Authors (see AUTHORS file)
//
// License for use of this code is detailed in the LICENSE file
package opus
import (
"fmt"
)
/*
#cgo pkg-config: opus
#include <opus.h>
*/
import "C"
type Error int
var _ error = Error(0)
// Libopus errors
const (
ErrOK = Error(C.OPUS_OK)
ErrBadArg = Error(C.OPUS_BAD_ARG)
ErrBufferTooSmall = Error(C.OPUS_BUFFER_TOO_SMALL)
ErrInternalError = Error(C.OPUS_INTERNAL_ERROR)
ErrInvalidPacket = Error(C.OPUS_INVALID_PACKET)
ErrUnimplemented = Error(C.OPUS_UNIMPLEMENTED)
ErrInvalidState = Error(C.OPUS_INVALID_STATE)
ErrAllocFail = Error(C.OPUS_ALLOC_FAIL)
)
// Error string (in human readable format) for libopus errors.
func (e Error) Error() string {
return fmt.Sprintf("opus: %s", C.GoString(C.opus_strerror(C.int(e))))
}