From 047ffe85cdae2b926bcd229d9920f76c99f00b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20C=20McCord?= Date: Mon, 4 Sep 2023 19:03:08 -0400 Subject: [PATCH] gofumpt and gci --- .envrc | 4 +++ .gitignore | 1 + application.go | 9 +++--- asterisk.go | 4 +-- bridge.go | 2 -- callerid.go | 4 +-- client.go | 1 - client/native/application.go | 3 +- client/native/asterisk.go | 3 +- client/native/client.go | 10 +++--- client/native/config.go | 3 +- client/native/logging.go | 3 +- config.go | 3 +- datetime_test.go | 4 +-- endpoint.go | 1 - events_gen.go | 1 - ext/bridgemon/bridgemon.go | 1 - ext/play/logger.go | 2 +- ext/play/options.go | 7 ++--- ext/play/play_test.go | 4 +-- ext/play/sequence.go | 3 +- ext/play/sequence_test.go | 4 +-- ext/play/session.go | 2 +- ext/record/logger.go | 2 +- ext/record/record.go | 3 +- flake.lock | 61 ++++++++++++++++++++++++++++++++++++ flake.nix | 59 ++++++++++++++++++++++++++++++++++ liveRecording.go | 1 - logger.go | 2 +- logging.go | 3 +- mailbox.go | 1 - originate.go | 1 - playback.go | 1 - sound.go | 1 - storedRecording.go | 1 - textMessage.go | 1 - 36 files changed, 164 insertions(+), 52 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..1305de82 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" +fi +use flake diff --git a/.gitignore b/.gitignore index 979847d2..8a90e75c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ _obj _test bin vendor/ +/.direnv/ # Architecture specific extensions/prefixes *.[568vq] diff --git a/application.go b/application.go index a05996a4..20545312 100644 --- a/application.go +++ b/application.go @@ -3,7 +3,6 @@ package ari // Application represents a communication path interacting with an Asterisk // server for application-level resources type Application interface { - // List returns the list of applications in Asterisk, optionally using the key for filtering List(*Key) ([]*Key, error) @@ -72,10 +71,10 @@ func (ah *ApplicationHandle) Data() (ad *ApplicationData, err error) { // Subscribe subscribes the application to an event source // event source may be one of: -// - channel: -// - bridge: -// - endpoint:/ (e.g. SIP/102) -// - deviceState: +// - channel: +// - bridge: +// - endpoint:/ (e.g. SIP/102) +// - deviceState: func (ah *ApplicationHandle) Subscribe(eventSource string) (err error) { err = ah.a.Subscribe(ah.key, eventSource) return diff --git a/asterisk.go b/asterisk.go index b259350a..6f842dbe 100644 --- a/asterisk.go +++ b/asterisk.go @@ -3,7 +3,6 @@ package ari // Asterisk represents a communication path for // the Asterisk server for system-level resources type Asterisk interface { - // Info gets data about the asterisk system Info(key *Key) (*AsteriskInfo, error) @@ -41,7 +40,7 @@ type BuildInfo struct { // ConfigInfo describes information about the Asterisk configuration type ConfigInfo struct { DefaultLanguage string `json:"default_language"` - MaxChannels int `json:"max_channels,omitempty"` //omitempty denotes an optional field, meaning the field may not be present if no value is assigned. + MaxChannels int `json:"max_channels,omitempty"` // omitempty denotes an optional field, meaning the field may not be present if no value is assigned. MaxLoad float64 `json:"max_load,omitempty"` MaxOpenFiles int `json:"max_open_files,omitempty"` Name string `json:"name"` // Asterisk system name @@ -68,7 +67,6 @@ type SystemInfo struct { // AsteriskVariables is an interface to interact with Asterisk global variables type AsteriskVariables interface { - // Get returns the value of the given variable; the ID field of the Key is the variable name Get(key *Key) (string, error) diff --git a/bridge.go b/bridge.go index 6e5f6dca..c7c6f3ca 100644 --- a/bridge.go +++ b/bridge.go @@ -3,7 +3,6 @@ package ari // Bridge represents a communication path to an // Asterisk server for working with bridge resources type Bridge interface { - // Create creates a bridge Create(key *Key, btype string, name string) (*BridgeHandle, error) @@ -78,7 +77,6 @@ type BridgeData struct { // BridgeAddChannelOptions describes additional options to be applied to a channel when it is joined to a bridge type BridgeAddChannelOptions struct { - // AbsorbDTMF indicates that DTMF coming from this channel will not be passed through to the bridge AbsorbDTMF bool diff --git a/callerid.go b/callerid.go index 7be713db..20fce49f 100644 --- a/callerid.go +++ b/callerid.go @@ -2,7 +2,7 @@ package ari import "errors" -//NOTE: Direct translation from ARI client 2.0 +// NOTE: Direct translation from ARI client 2.0 // CallerIDFromString interprets the provided string // as a CallerID. Usually, this string will be of the following forms: @@ -10,7 +10,7 @@ import "errors" // - // - "Name" number func CallerIDFromString(src string) (*CallerID, error) { - //TODO: implement complete callerid parser + // TODO: implement complete callerid parser return nil, errors.New("CallerIDFromString not yet implemented") } diff --git a/client.go b/client.go index 6f469f2c..6e14b9cb 100644 --- a/client.go +++ b/client.go @@ -4,7 +4,6 @@ package ari // with an Asterisk ARI server. It is agnostic to transport // and implementation. type Client interface { - // ApplicationName returns the ARI application name by which this client is connected ApplicationName() string diff --git a/client/native/application.go b/client/native/application.go index e8ccbec3..213b75da 100644 --- a/client/native/application.go +++ b/client/native/application.go @@ -3,8 +3,9 @@ package native import ( "fmt" - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Application is a native implementation of ARI's Application functions diff --git a/client/native/asterisk.go b/client/native/asterisk.go index cd06971e..86a4a334 100644 --- a/client/native/asterisk.go +++ b/client/native/asterisk.go @@ -3,8 +3,9 @@ package native import ( "fmt" - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Asterisk provides the ARI Asterisk accessors for a native client diff --git a/client/native/client.go b/client/native/client.go index 2727ea35..dd0b421c 100644 --- a/client/native/client.go +++ b/client/native/client.go @@ -9,20 +9,20 @@ import ( "sync" "time" + "github.com/inconshreveable/log15" + "github.com/rotisserie/eris" + "golang.org/x/net/websocket" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" "github.com/CyCoreSystems/ari/v6/stdbus" - "github.com/rotisserie/eris" - - "github.com/inconshreveable/log15" - "golang.org/x/net/websocket" ) // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/client/native/config.go b/client/native/config.go index 03fb885c..a67af4ad 100644 --- a/client/native/config.go +++ b/client/native/config.go @@ -1,8 +1,9 @@ package native import ( - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Config provides the ARI Configuration accessors for a native client diff --git a/client/native/logging.go b/client/native/logging.go index 230f995d..53e97d25 100644 --- a/client/native/logging.go +++ b/client/native/logging.go @@ -1,8 +1,9 @@ package native import ( - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Logging provides the ARI Logging accessors for a native client diff --git a/config.go b/config.go index 91b1fcf6..d0677340 100644 --- a/config.go +++ b/config.go @@ -9,7 +9,6 @@ import ( // Config represents a transport to the asterisk // config ARI resource. type Config interface { - // Get gets the reference to a config object Get(key *Key) *ConfigHandle @@ -40,7 +39,7 @@ func (cd *ConfigData) ID() string { return fmt.Sprintf("%s/%s/%s", cd.Class, cd.Type, cd.Name) } -//ConfigTupleList wrap a list for asterisk ari require. +// ConfigTupleList wrap a list for asterisk ari require. type ConfigTupleList struct { Fields []ConfigTuple `json:"fields"` } diff --git a/datetime_test.go b/datetime_test.go index 76cef74c..d8f1b66b 100644 --- a/datetime_test.go +++ b/datetime_test.go @@ -16,7 +16,7 @@ var dtMarshalTests = []struct { Output string HasError bool }{ - {dtTest{DateTime(time.Date(2005, 02, 04, 13, 12, 6, 0, time.UTC))}, `{"dt":"2005-02-04T13:12:06.000+0000"}`, false}, + {dtTest{DateTime(time.Date(2005, 0o2, 0o4, 13, 12, 6, 0, time.UTC))}, `{"dt":"2005-02-04T13:12:06.000+0000"}`, false}, } var dtUnmarshalTests = []struct { @@ -24,7 +24,7 @@ var dtUnmarshalTests = []struct { Output dtTest HasError bool }{ - {`{"dt":"2005-02-04T13:12:06.000+0000"}`, dtTest{DateTime(time.Date(2005, 02, 04, 13, 12, 6, 0, time.UTC))}, false}, + {`{"dt":"2005-02-04T13:12:06.000+0000"}`, dtTest{DateTime(time.Date(2005, 0o2, 0o4, 13, 12, 6, 0, time.UTC))}, false}, {`{"dt":"2x05-02-04T13:12:06.000+0000"}`, dtTest{}, true}, {`{"dt": 0 }`, dtTest{}, true}, } diff --git a/endpoint.go b/endpoint.go index cf5fbbea..7f4a2551 100644 --- a/endpoint.go +++ b/endpoint.go @@ -11,7 +11,6 @@ const EndpointIDSeparator = "|" // TODO: confirm separator isn't terrible // Endpoint represents a communication path to an Asterisk server // for endpoint resources type Endpoint interface { - // List lists the endpoints List(filter *Key) ([]*Key, error) diff --git a/events_gen.go b/events_gen.go index 47b416bd..74756b5e 100644 --- a/events_gen.go +++ b/events_gen.go @@ -100,7 +100,6 @@ func init() { Events.StasisEnd = "StasisEnd" Events.StasisStart = "StasisStart" Events.TextMessageReceived = "TextMessageReceived" - } // DecodeEvent converts a JSON-encoded event to an ARI event. diff --git a/ext/bridgemon/bridgemon.go b/ext/bridgemon/bridgemon.go index adf8e188..7e84f7a9 100644 --- a/ext/bridgemon/bridgemon.go +++ b/ext/bridgemon/bridgemon.go @@ -135,7 +135,6 @@ func (m *Monitor) Key() *ari.Key { // destoyed. // // NOTE: the user should NEVER close this channel directly. -// func (m *Monitor) Watch() <-chan *ari.BridgeData { ch := make(chan *ari.BridgeData) diff --git a/ext/play/logger.go b/ext/play/logger.go index 572b06ea..4b8da3cd 100644 --- a/ext/play/logger.go +++ b/ext/play/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/ext/play/options.go b/ext/play/options.go index c6db62f0..f491731e 100644 --- a/ext/play/options.go +++ b/ext/play/options.go @@ -332,12 +332,11 @@ func PlaybackStartTimeout(timeout time.Duration) OptionFunc { // DigitTimeouts sets the digit timeouts. Passing a negative value to any of these indicates that the default value (shown in parentheses below) should be used. // -// - First digit timeout (4 sec): The time (after the stop of the audio) to wait for the first digit to be received +// - First digit timeout (4 sec): The time (after the stop of the audio) to wait for the first digit to be received // -// - Inter digit timeout (3 sec): The time (after receiving a digit) to wait for the _next_ digit to be received -// -// - Overall digit timeout (3 min): The maximum amount of time to wait (after the stop of the audio) for digits to be received, regardless of the digit frequency +// - Inter digit timeout (3 sec): The time (after receiving a digit) to wait for the _next_ digit to be received // +// - Overall digit timeout (3 min): The maximum amount of time to wait (after the stop of the audio) for digits to be received, regardless of the digit frequency func DigitTimeouts(first, inter, overall time.Duration) OptionFunc { return func(o *Options) error { if first >= 0 { diff --git a/ext/play/play_test.go b/ext/play/play_test.go index d2d72485..aaafd013 100644 --- a/ext/play/play_test.go +++ b/ext/play/play_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/client/arimocks" - - "github.com/stretchr/testify/mock" ) type playStagedTest struct { diff --git a/ext/play/sequence.go b/ext/play/sequence.go index 5a26b238..2091197a 100644 --- a/ext/play/sequence.go +++ b/ext/play/sequence.go @@ -4,9 +4,10 @@ import ( "context" "time" + "github.com/rotisserie/eris" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" - "github.com/rotisserie/eris" ) // sequence represents an audio sequence playback session diff --git a/ext/play/sequence_test.go b/ext/play/sequence_test.go index 3b015a64..6b517a4b 100644 --- a/ext/play/sequence_test.go +++ b/ext/play/sequence_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/client/arimocks" - - "github.com/stretchr/testify/mock" ) type sequenceTest struct { diff --git a/ext/play/session.go b/ext/play/session.go index b2a86400..45d9d921 100644 --- a/ext/play/session.go +++ b/ext/play/session.go @@ -242,7 +242,7 @@ func (s *playSession) Stop() { } s.mu.Lock() - + if !s.closed { s.closed = true close(s.done) diff --git a/ext/record/logger.go b/ext/record/logger.go index b69526c9..bc2d7f8f 100644 --- a/ext/record/logger.go +++ b/ext/record/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/ext/record/record.go b/ext/record/record.go index 67e4254e..27b0b15a 100644 --- a/ext/record/record.go +++ b/ext/record/record.go @@ -7,9 +7,10 @@ import ( "sync" "time" + "github.com/rotisserie/eris" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" - "github.com/rotisserie/eris" ) var ( diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..c5ab91b6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1693663421, + "narHash": "sha256-ImMIlWE/idjcZAfxKK8sQA7A1Gi/O58u5/CJA+mxvl8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e56990880811a451abd32515698c712788be5720", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..eac41211 --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = "mono devshell"; + inputs = { + #nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + write-mailmap = pkgs.buildGoModule rec { + name = "write_mailmap"; + src = pkgs.fetchFromGitHub { + owner = "CyCoreSystems"; + repo = "write_mailmap"; + rev = "v0.3.0"; + sha256 = "sha256-LzLLEtsWLeIOnlY1pygAOhTsGiWfISnuVF/jeoHHzaw="; + }; + + # There are no upstream packages, so vendor hash is null. + vendorHash = null; + }; + + gci = pkgs.buildGoModule rec { + name = "gci"; + src = pkgs.fetchFromGitHub { + owner = "daixiang0"; + repo = "gci"; + rev = "v0.10.1"; + sha256 = "sha256-/YR61lovuYw+GEeXIgvyPbesz2epmQVmSLWjWwKT4Ag="; + }; + + # Switch to fake vendor sha for upgrades: + #vendorSha256 = pkgs.lib.fakeSha256; + vendorSha256 = "sha256-g7htGfU6C2rzfu8hAn6SGr0ZRwB8ZzSf9CgHYmdupE8="; + }; + + cclint = pkgs.writeScriptBin "lint" '' + cd $(git rev-parse --show-toplevel) + gofumpt -w . + gci write --skip-generated -s standard -s default -s "Prefix(github.com/CyCoreSystems)" . + golangci-lint run + ''; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + buf + cclint + gci + go-tools + write-mailmap + ]; + }; + }); +} diff --git a/liveRecording.go b/liveRecording.go index 5aefd9ec..001f9afd 100644 --- a/liveRecording.go +++ b/liveRecording.go @@ -5,7 +5,6 @@ import "sync" // LiveRecording represents a communication path interacting with an Asterisk // server for live recording resources type LiveRecording interface { - // Get gets the Recording by type Get(key *Key) *LiveRecordingHandle diff --git a/logger.go b/logger.go index 4b1ef17d..fcd3221f 100644 --- a/logger.go +++ b/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/logging.go b/logging.go index f70a1510..032a5dd7 100644 --- a/logging.go +++ b/logging.go @@ -3,7 +3,6 @@ package ari // Logging represents a communication path to an // Asterisk server for working with logging resources type Logging interface { - // Create creates a new log. The levels are a comma-separated list of // logging levels on which this channel should operate. The name of the // channel should be the key's ID. @@ -43,7 +42,7 @@ type LogData struct { Status string `json:"status"` } -// NewLogHandle builds a new log handle given the `Key` and `Logging`` client +// NewLogHandle builds a new log handle given the `Key` and `Logging“ client func NewLogHandle(key *Key, l Logging) *LogHandle { return &LogHandle{ key: key, diff --git a/mailbox.go b/mailbox.go index 3c85ff01..0471fddd 100644 --- a/mailbox.go +++ b/mailbox.go @@ -3,7 +3,6 @@ package ari // Mailbox is the communication path to an Asterisk server for // operating on mailbox resources type Mailbox interface { - // Get gets a handle to the mailbox for further operations Get(key *Key) *MailboxHandle diff --git a/originate.go b/originate.go index 5e863494..b433fedd 100644 --- a/originate.go +++ b/originate.go @@ -2,7 +2,6 @@ package ari // OriginateRequest defines the parameters for the creation of a new Asterisk channel type OriginateRequest struct { - // Endpoint is the name of the Asterisk resource to be used to create the // channel. The format is tech/resource. // diff --git a/playback.go b/playback.go index 1251bf72..09e4d224 100644 --- a/playback.go +++ b/playback.go @@ -3,7 +3,6 @@ package ari // Playback represents a communication path for interacting // with an Asterisk server for playback resources type Playback interface { - // Get gets the handle to the given playback ID Get(key *Key) *PlaybackHandle diff --git a/sound.go b/sound.go index 15925233..3660e5f1 100644 --- a/sound.go +++ b/sound.go @@ -3,7 +3,6 @@ package ari // Sound represents a communication path to // the asterisk server for Sound resources type Sound interface { - // List returns available sounds limited by the provided filters. // Valid filters are "lang", "format", and nil (no filter) List(filters map[string]string, keyFilter *Key) ([]*Key, error) diff --git a/storedRecording.go b/storedRecording.go index 093b709d..b50cf2f3 100644 --- a/storedRecording.go +++ b/storedRecording.go @@ -3,7 +3,6 @@ package ari // StoredRecording represents a communication path interacting with an Asterisk // server for stored recording resources type StoredRecording interface { - // List lists the recordings List(filter *Key) ([]*Key, error) diff --git a/textMessage.go b/textMessage.go index 372b0d7c..69830020 100644 --- a/textMessage.go +++ b/textMessage.go @@ -2,7 +2,6 @@ package ari // TextMessage needs some verbiage here type TextMessage interface { - // Send() sends a text message to an endpoint Send(from, tech, resource, body string, vars map[string]string) error