summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-02-04Release share v0.53.0 (2024-02-04)v0.53.0Shulhan
=== New features * test/mock: implement mock for crypto [rand.Reader] The RandReader implement [io.Reader]. To provide predictable result, the RandReader is seeded with slice of bytes. A call to Read will fill the passed bytes with those seed. For example, given seed as "abc" (length is three), calling Read with bytes length five will return "abcab". * lib/sql: add new type Meta Meta contains the DML meta data, including driver name, list of column names, list of column holders, and list of values. The Meta type replace the Row type. * lib/path: new package to work with path The path package provide a new type Route, detached from "lib/http". A Route represent a parsed path. A path can have a key, or binding, that can be replaced with string value. For example, "/org/:user/:repo" have two keys "user" and "repo". Route handle the path in case-insensitive manner. === Bug fixes * _bin/go-mod-tip: use committer timestamp instead of author timestamp If the tip is rebased to upstream, the author timestamp is not changes, but the commit timestamp changes. === Enhancements * lib/totp: add method GenerateWithTime and GenerateNWithTime The GenerateWithTime and GenerateNWithTime accept parameter [time.Time] as the relative time for generated password. * lib/http: add support for If-Modified-Since in HandleFS If the node modification time is less than requested time value in request header If-Modified-Since, server will response with 304 Not Modified. * lib/http: refactoring Range request, limit content served by server When server receive, GET /big Range: bytes=0- and the requested resources is quite larger, where writing all content of file result in i/o timeout, it is best practice [1][2] if the server write only partial content and let the client continue with the subsequent Range request. In the above case, the server should response with, HTTP/1.1 206 Partial content Content-Range: bytes 0-<limit>/<size> Content-Length: <limit> Where limit is maximum packet that is reasonable [3] for most of the client. In this server we choose 8MB as limit. * lib/http: add method Head to Client The Head method send the HEAD request to path, with optional headers, and params in query parameters. * lib/ini: add method Keys:: The Keys method return sorted list of all section, subsection, and variables as string where each of them separated by ":", for example "section:sub:var".
2024-02-04lib/memfs: protect internal [DirWatcher.fileWatcher] with mutexShulhan
This is to fix several flaky tests on ExampleDirWatcher [1]. [1] https://github.com/shuLhan/share/actions/runs/7765975142 [2] https://github.com/shuLhan/share/actions/runs/7672754239
2024-02-03lib/memfs: fix flaky test on [Memfs.Get] with refreshShulhan
The test is flaky because we use range over map of [tdata.Input]. Since range over map will return random key, there is possibility that the first test is writing "/dir-a/dir-b/file2" not "/dir-a/dir-b/file".
2024-01-30lib/sql: refactor WhereFields to join where condition with holder as isShulhan
When binding parameter with BindWhere, the first parameter will be joined with the holder. For example, BindWhere("colname>=", p) will result in "colname>=$1". While at it, set offset based on [Meta.kind].
2024-01-29lib/totp: add method GenerateWithTime and GenerateNWithTimeShulhan
The GenerateWithTime and GenerateNWithTime accept parameter [time.Time] as the relative time for generated password.
2024-01-29test/mock: implement mock for crypto [rand.Reader]Shulhan
The RandReader implement [io.Reader]. To provide predictable result, the RandReader is seeded with slice of bytes. A call to Read will fill the passed bytes with those seed. For example, given seed as "abc" (length is three), calling Read with bytes length five will return "abcab".
2024-01-27lib/sql: remove type TableShulhan
This type has never been used and the implementation is not correct.
2024-01-27lib/sql: support update, bind where condition, and subquery in MetaShulhan
This changes add parameter kind to NewMeta, which define the kind of DML to be mapped by Meta. The method Add renamed to Bind, and AddWhere renamed to BindWhere. New methods added to Meta, - Sub return the child of Meta for building subquery, - UpdateValues return the merged of ListValue and ListWhereValue for DML UPDATE - WhereFields return string that merge the ListWhereCond and ListHolder separated by "="
2024-01-25lib/sql: add method WhereHolder to Meta typeShulhan
The WhereHolder method generate string of holder, for example "$1,$2,...", based on number of item added with [Meta.AddWhere]. Similar to method Holders but for where condition.
2024-01-25lib/path: add method Keys and NKey, and export IsKeyExistsShulhan
The Keys method return list of key in path. The NKey method return the number of key in path. The IsKeyExists return true if the key exist in Route; otherwise it will return false.
2024-01-25lib/sql: add new type MetaShulhan
Meta contains the DML meta data, including driver name, list of column names, list of column holders, and list of values. The Meta type replace the Row type.
2024-01-25lib/path: add example for [Route.Parse]Shulhan
2024-01-25lib/path: add method Set to RouteShulhan
The Set method set or replace the key's value in path with parameter val. If the key exist it will return true; otherwise it will return false. This changes remove unnecessary field key in routeNode and optimize the String method using [strings.Builder].
2024-01-25lib/path: new package to work with pathShulhan
The path package provide a new type Route, detached from "lib/http". A Route represent a parsed path. A path can have a key, or binding, that can be replaced with string value. For example, "/org/:user/:repo" have two keys "user" and "repo". Route handle the path in case-insensitive manner.
2024-01-24lib/http: simplify parameter names in Client method for godocShulhan
The Client methods when rendered in godoc is quite long make it uneasy to read.
2024-01-24all: fix the warnings from linter reviveShulhan
This rename all variable "Ids" into "ListID".
2024-01-24_bin/go-mod-tip: use committer timestamp instead of author timestampShulhan
If the tip is rebased to upstream, the author timestamp is not changes, but the commit timestamp changes.
2024-01-24go.mod: update all dependenciesShulhan
2024-01-24lib/http: add support for If-Modified-Since in HandleFSShulhan
If the node modification time is less than requested time value in request header If-Modified-Since, server will response with 304 Not Modified.
2024-01-24lib/http: use raw string literal for string constantsShulhan
While at it, group the constants by its values.
2024-01-24lib/http: update doc to use comment linksShulhan
2024-01-24lib/http: refactoring Range request, limit content served by serverShulhan
When server receive, GET /big Range: bytes=0- and the requested resources is quite larger, where writing all content of file result in i/o timeout, it is best practice [1][2] if the server write only partial content and let the client continue with the subsequent Range request. In the above case, the server should response with, HTTP/1.1 206 Partial content Content-Range: bytes 0-<limit>/<size> Content-Length: <limit> Where limit is maximum packet that is reasonable [3] for most of the client. In this server we choose 8MB as limit. [1]: https://stackoverflow.com/questions/63614008/how-best-to-respond-to-an-open-http-range-request [2]: https://bugzilla.mozilla.org/show_bug.cgi?id=570755 [3]: https://docs.aws.amazon.com/whitepapers/latest/s3-optimizing-performance-best-practices/use-byte-range-fetches.html
2024-01-18lib/http: add method Head to ClientShulhan
The Head method send the HEAD request to path, with optional headers, and params in query parameters.
2024-01-14lib/ini: add method KeysShulhan
The Keys method return sorted list of all section, subsection, and variables as string where each of them separated by ":", for example "section:sub:var".
2024-01-14lib/ini: use method IsExported in marshalStructShulhan
Since Go 1.17, the [reflect.StructField] add method IsExported which give clear indication that the field is exported rather than checking not-empty PkgPath.
2024-01-06Release share v0.52.0 (2024-01-06)v0.52.0Shulhan
=== New features * ssh/config: add method MarshalText and WriteTo * lib/ssh: implement method Output on Client * ssh/sftp: implement method MkdirAll on Client * cmd/httpdfs: implement [libhttp.Server] with [memfs.MemFS] === Breaking changes * ssh/config: refactoring the Config merge * ssh/config: add parameter Config to NewSection * lib/ssh: add parameter context to Execute method * lib/time: remove UnixMicro and UnixMilli * lib/io: removed, this package has been merged into "lib/os" * lib/parser: removed, this package has been merged into lib/strings === Bug fixes * ssh/config: fix setting the default values * ssh/config: set the Hostname if its not set on [Config.Get] * http/sseclient: fix data race on [Client.Close] * http/sseclient: fix Retry value not set to millisecond * ssh/sftp: fix Stat on empty remote file name * ssh/sftp: fix non-nil returned error on Close === Enhancements * ssh/config: merge the Section slice values on [Section.merge] * ssh/config: set the default UserKnownHostsFile in setDefaults
2023-12-26ssh/config: refactoring the Config mergeShulhan
This changes rename method [Config.Prepend] to [Config.Merge]. The way that how the other Config merged is changed. Instead of appending all of other's sections into the current Config, append the other Config instance to the current instance of Config. During [Config.Get] the top Config will be evaluated first, and then the other Config is evaluated in order of Merge.
2023-12-26ssh/config: merge the Section slice values on [Section.merge]Shulhan
Instead of using [Section.Set], set the key-value directly. While at it, merge the certificateFile, IdentityFile, knownHostFiles, and sendEnv.
2023-12-25ssh/config: set the default UserKnownHostsFile in setDefaultsShulhan
While at it, unfold each value of IdentityFile and UserKnownHostsFile in setDefaults, by expanding "~" into user's home directory or joining with "config" directory if its relative.
2023-12-25ssh/config: update comment on [Config.Get]Shulhan
Make it clear that the passed parameter is a host name and the returned section will contains default values if no host or match found.
2023-12-25ssh/config: add parameter Config to NewSectionShulhan
This changes how the Section and parser initialized. Previously, the Config depends on the parser to set the workDir and homeDir and Section depends on Config only on Get; now its the other way around, from top to bottom. Config initialized first, then parser initialized using Config instance, and then Section initialized also using Config instance.
2023-12-25ssh/config: fix setting the default valuesShulhan
The field default value should be set on Get, after all the Host or Match fields merged. In this way, if the field key already set, its not overridden by the default value or subsequent Host or Match vaue.
2023-12-22lib/ssh: add parameter context to Execute methodShulhan
This changes require the fork of our golang.org/x/crypto.
2023-12-22go.mod: update golang.org/x/crypto to v0.17.0Shulhan
2023-12-19ssh/config: set the Hostname if its not set on [Config.Get]Shulhan
Per manual ssh_config(5) on Hostname, The default is the name given on the command line. So, if the requested host name match with one of Host or Match, but Hostname is not set, it should be default to the requested parameter name.
2023-12-19ssh/config: rewrite unit tests for [Config.Get] using [lib.test.Data]Shulhan
Using test.Data make the output easy to audit and modified.
2023-12-19ssh/config: set default section name to '*' if parameter is emptyShulhan
2023-12-18ssh/config: fix negate not resetted when parsing new section MatchShulhan
2023-12-18ssh/config: add method MarshalText and WriteToShulhan
The MarshalText method encode the Section back to ssh_config format with two spaces as indentation in key. The WriteTo method marshal the Section into text and write it to [io.Writer] w.
2023-12-17http/sseclient: fix data race on [Client.Close]Shulhan
The data race happened when Close set conn to nil but the consume method still on Read. The fix is by waiting for 100ms so consume goroutine can check if closeq is triggered from Close or not.
2023-12-17http/sseclient: fix Retry value not set to millisecondShulhan
When client receive "retry:" message, the value is in millisecond, but when we store it we only convert it to [time.Duration] which default to nanosecond. While at it, update comments on field [Client.Retry] and [Client.Insecure].
2023-12-17lib/time: un-export the variable NowShulhan
The original idea of providing Now is to mock the current time in testing Scheduler. Since this variable can be overridden by other packages, it is not safe to export it, hence we un-export it here so it can be used internal only.
2023-12-17lib/time: remove UnixMicro and UnixMilliShulhan
Both of those methods has been added into standard library as [Time.UnixMicro] and [Time.UnixMilli] since Go 1.17.
2023-12-17lib/ssh: implement method Output on ClientShulhan
The Output method run the command and return its standard output and error as is. Any other error beside standard error, like connection, will be returned as error.
2023-12-17ssh/sftp: implement method MkdirAll on ClientShulhan
The MkdirAll create directory on the server, from left to right. Each directory is separated by '/', where the left part is the parent of the right part. This method is similar to [os.MkdirAll].
2023-12-17ssh/sftp: fix Stat on empty remote file nameShulhan
The implementation of SSH server for Stat is not consistent with the RFC. The RFC mentioned that An empty path name is valid, and it refers to the user's default directory (usually the user's home directory). But this only working on some command, like Mkdir, but not Stat.
2023-12-17ssh/sftp: use fixed slice length when converting in unpackFileAttrsShulhan
This is to make sure that the passed value is in the correct, expected size.
2023-12-17ssh/sftp: update comments to use references [...]Shulhan
2023-12-13ssh/sftp: fix non-nil returned error on CloseShulhan
2023-12-13lib/io: removed, this package has been merged into lib/osShulhan
While some functions are merged to lib/os, some are not used anymore like io.Reader.