Skip to content

Commit 2144dc6

Browse files
committed
procfs: change Unix to UNIX per Go conventions
Signed-off-by: Matt Layher <[email protected]>
1 parent 0f3e0ad commit 2144dc6

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

Diff for: net_unix.go

+32-34
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,39 @@ const (
4242
netUnixStateDisconnected = 4
4343
)
4444

45-
// NetUnixType is the type of the type field.
46-
type NetUnixType uint64
45+
// NetUNIXType is the type of the type field.
46+
type NetUNIXType uint64
4747

48-
// NetUnixFlags is the type of the flags field.
49-
type NetUnixFlags uint64
48+
// NetUNIXFlags is the type of the flags field.
49+
type NetUNIXFlags uint64
5050

51-
// NetUnixState is the type of the state field.
52-
type NetUnixState uint64
51+
// NetUNIXState is the type of the state field.
52+
type NetUNIXState uint64
5353

54-
// NetUnixLine represents a line of /proc/net/unix.
55-
type NetUnixLine struct {
54+
// NetUNIXLine represents a line of /proc/net/unix.
55+
type NetUNIXLine struct {
5656
KernelPtr string
5757
RefCount uint64
5858
Protocol uint64
59-
Flags NetUnixFlags
60-
Type NetUnixType
61-
State NetUnixState
59+
Flags NetUNIXFlags
60+
Type NetUNIXType
61+
State NetUNIXState
6262
Inode uint64
6363
Path string
6464
}
6565

66-
// NetUnix holds the data read from /proc/net/unix.
67-
type NetUnix struct {
68-
Rows []*NetUnixLine
66+
// NetUNIX holds the data read from /proc/net/unix.
67+
type NetUNIX struct {
68+
Rows []*NetUNIXLine
6969
}
7070

71-
// NetUnix returns data read from /proc/net/unix.
72-
func (fs FS) NetUnix() (*NetUnix, error) {
73-
// TODO: this function name and type should be "NetUNIX" per Go convention.
74-
// Consider changing at a later time.
71+
// NetUNIX returns data read from /proc/net/unix.
72+
func (fs FS) NetUNIX() (*NetUNIX, error) {
7573
return readNetUNIX(fs.proc.Path("net/unix"))
7674
}
7775

7876
// readNetUNIX reads data in /proc/net/unix format from the specified file.
79-
func readNetUNIX(file string) (*NetUnix, error) {
77+
func readNetUNIX(file string) (*NetUNIX, error) {
8078
// This file could be quite large and a streaming read is desirable versus
8179
// reading the entire contents at once.
8280
f, err := os.Open(file)
@@ -89,7 +87,7 @@ func readNetUNIX(file string) (*NetUnix, error) {
8987
}
9088

9189
// parseNetUNIX creates a NetUnix structure from the incoming stream.
92-
func parseNetUNIX(r io.Reader) (*NetUnix, error) {
90+
func parseNetUNIX(r io.Reader) (*NetUNIX, error) {
9391
// Begin scanning by checking for the existence of Inode.
9492
s := bufio.NewScanner(r)
9593
s.Scan()
@@ -105,7 +103,7 @@ func parseNetUNIX(r io.Reader) (*NetUnix, error) {
105103
minFields++
106104
}
107105

108-
var nu NetUnix
106+
var nu NetUNIX
109107
for s.Scan() {
110108
line := s.Text()
111109
item, err := nu.parseLine(line, hasInode, minFields)
@@ -123,7 +121,7 @@ func parseNetUNIX(r io.Reader) (*NetUnix, error) {
123121
return &nu, nil
124122
}
125123

126-
func (u *NetUnix) parseLine(line string, hasInode bool, min int) (*NetUnixLine, error) {
124+
func (u *NetUNIX) parseLine(line string, hasInode bool, min int) (*NetUNIXLine, error) {
127125
fields := strings.Fields(line)
128126

129127
l := len(fields)
@@ -164,7 +162,7 @@ func (u *NetUnix) parseLine(line string, hasInode bool, min int) (*NetUnixLine,
164162
}
165163
}
166164

167-
n := &NetUnixLine{
165+
n := &NetUNIXLine{
168166
KernelPtr: kernelPtr,
169167
RefCount: users,
170168
Type: typ,
@@ -188,42 +186,42 @@ func (u *NetUnix) parseLine(line string, hasInode bool, min int) (*NetUnixLine,
188186
return n, nil
189187
}
190188

191-
func (u NetUnix) parseUsers(s string) (uint64, error) {
189+
func (u NetUNIX) parseUsers(s string) (uint64, error) {
192190
return strconv.ParseUint(s, 16, 32)
193191
}
194192

195-
func (u NetUnix) parseType(s string) (NetUnixType, error) {
193+
func (u NetUNIX) parseType(s string) (NetUNIXType, error) {
196194
typ, err := strconv.ParseUint(s, 16, 16)
197195
if err != nil {
198196
return 0, err
199197
}
200198

201-
return NetUnixType(typ), nil
199+
return NetUNIXType(typ), nil
202200
}
203201

204-
func (u NetUnix) parseFlags(s string) (NetUnixFlags, error) {
202+
func (u NetUNIX) parseFlags(s string) (NetUNIXFlags, error) {
205203
flags, err := strconv.ParseUint(s, 16, 32)
206204
if err != nil {
207205
return 0, err
208206
}
209207

210-
return NetUnixFlags(flags), nil
208+
return NetUNIXFlags(flags), nil
211209
}
212210

213-
func (u NetUnix) parseState(s string) (NetUnixState, error) {
211+
func (u NetUNIX) parseState(s string) (NetUNIXState, error) {
214212
st, err := strconv.ParseInt(s, 16, 8)
215213
if err != nil {
216214
return 0, err
217215
}
218216

219-
return NetUnixState(st), nil
217+
return NetUNIXState(st), nil
220218
}
221219

222-
func (u NetUnix) parseInode(s string) (uint64, error) {
220+
func (u NetUNIX) parseInode(s string) (uint64, error) {
223221
return strconv.ParseUint(s, 10, 64)
224222
}
225223

226-
func (t NetUnixType) String() string {
224+
func (t NetUNIXType) String() string {
227225
switch t {
228226
case netUnixTypeStream:
229227
return "stream"
@@ -235,7 +233,7 @@ func (t NetUnixType) String() string {
235233
return "unknown"
236234
}
237235

238-
func (f NetUnixFlags) String() string {
236+
func (f NetUNIXFlags) String() string {
239237
switch f {
240238
case netUnixFlagListen:
241239
return "listen"
@@ -244,7 +242,7 @@ func (f NetUnixFlags) String() string {
244242
}
245243
}
246244

247-
func (s NetUnixState) String() string {
245+
func (s NetUNIXState) String() string {
248246
switch s {
249247
case netUnixStateUnconnected:
250248
return "unconnected"

Diff for: net_unix_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestNetUnix(t *testing.T) {
3131
t.Fatalf("failed to open procfs: %v", err)
3232
}
3333

34-
got, err := fs.NetUnix()
34+
got, err := fs.NetUNIX()
3535
if err != nil {
3636
t.Fatalf("failed to get UNIX socket data: %v", err)
3737
}
@@ -53,12 +53,12 @@ func TestNetUnixNoInode(t *testing.T) {
5353
testNetUNIX(t, noCheckInode, got)
5454
}
5555

56-
func testNetUNIX(t *testing.T, testInode bool, got *NetUnix) {
56+
func testNetUNIX(t *testing.T, testInode bool, got *NetUNIX) {
5757
t.Helper()
5858

5959
// First verify that the input data matches a prepopulated structure.
6060

61-
want := []*NetUnixLine{
61+
want := []*NetUNIXLine{
6262
{
6363
KernelPtr: "0000000000000000",
6464
RefCount: 2,
@@ -120,23 +120,23 @@ func testNetUNIX(t *testing.T, testInode bool, got *NetUnix) {
120120
// Now test the field enumerations and ensure they match up correctly
121121
// with the constants used to generate readable strings.
122122

123-
wantFlags := []NetUnixFlags{
123+
wantFlags := []NetUNIXFlags{
124124
netUnixFlagListen,
125125
netUnixFlagListen,
126126
netUnixFlagDefault,
127127
netUnixFlagDefault,
128128
netUnixFlagDefault,
129129
}
130130

131-
wantType := []NetUnixType{
131+
wantType := []NetUNIXType{
132132
netUnixTypeStream,
133133
netUnixTypeSeqpacket,
134134
netUnixTypeDgram,
135135
netUnixTypeStream,
136136
netUnixTypeStream,
137137
}
138138

139-
wantState := []NetUnixState{
139+
wantState := []NetUNIXState{
140140
netUnixStateUnconnected,
141141
netUnixStateUnconnected,
142142
netUnixStateUnconnected,
@@ -145,9 +145,9 @@ func testNetUNIX(t *testing.T, testInode bool, got *NetUnix) {
145145
}
146146

147147
var (
148-
gotFlags []NetUnixFlags
149-
gotType []NetUnixType
150-
gotState []NetUnixState
148+
gotFlags []NetUNIXFlags
149+
gotType []NetUNIXType
150+
gotState []NetUNIXState
151151
)
152152

153153
for _, r := range got.Rows {

0 commit comments

Comments
 (0)