-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes.go
66 lines (59 loc) · 1.57 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gphoto2
/** \file
*
* \author Copyright 2020 Jon Molin
*
* \note
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* \note
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* \note
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/*
#cgo LDFLAGS: -lgphoto2 -lgphoto2_port
#include <stdlib.h>
#include <gphoto2/gphoto2.h>
*/
import "C"
import (
"fmt"
// "unsafe"
)
type GphotoError struct {
msg string
extra string
Code int
}
func (g *GphotoError) Error() string {
if g.extra != "" {
return fmt.Sprintf("%s (%s): %d", g.msg, g.extra, g.Code)
}
return fmt.Sprintf("%s: %d", g.msg, g.Code)
}
func newError(e string, code int) error {
msg := e
extra := ""
if code >= libGphotoErrEnd && code <= libGphotoErrStart {
m := C.gp_result_as_string(C.int(code))
// defer C.free(unsafe.Pointer(m)) // should this one be freed or not?
msg = C.GoString(m)
if msg == "" {
msg = e
} else {
extra = e
}
}
return &GphotoError{msg: msg, Code: code, extra: extra}
}