dev-utils

module
v0.0.0-...-d59c728 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2021 License: Apache-2.0

README

dev-utils

Try to give a comprehensive list of utilities during Go development. Keep small and elegant.

GitHub licensemade-with-Gogopherbadger-tag-do-not-editPRs WelcomeMaintenance

install

go get github.com/csimplestring/dev-utils

features

  • file watcher
  • stop watch
  • ring buffer matcher

examples

  • file watcher: The file watch will detects if the file is changed or not, and execute a callback if it is changed.
    // In this example, the last-modified-time determines if a file is modified or not.
    // if you want to use the md5 sum of a file content as the *state*, you can create your own Monitor to detect if the file state is changed by implementing the UpdateModifer interface.

    w, err := NewWatcher(tmpfile.Name(), &LastModifiedMonitor{})
	assert.NoError(t, err)

	cnt := 0
	cb := func(path string) {
		cnt++
	}

    // file is not changed, cnt == 0
	err = w.Check(cb)
	assert.NoError(t, err)
	assert.Equal(t, 0, cnt)

	_, err = tmpfile.WriteString("add")
	assert.NoError(t, err)

    // file is changed, last modified time is updated, cnt == 1
	err = w.Check(cb)
	assert.NoError(t, err)
	assert.Equal(t, 1, cnt)

  • stop watch: the stop watch sometimes can help developers to log the running time of functions, code blocks etc. See Example.

  • ring buffer matcher: A RingBuffer that can be used to scan byte sequences for subsequences. This class implements an efficient naive search algorithm, which allows the user of the library to identify byte sequences in a stream on-the-fly so that the stream can be segmented without having to buffer the data.

Directories

Path Synopsis
pkg
buf

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL