Skip to content

Modernize for Go 1.26 - #1357

Merged
brandur merged 1 commit into
masterfrom
brandur-go-1.26-modernize
Aug 22, 2026
Merged

Modernize for Go 1.26#1357
brandur merged 1 commit into
masterfrom
brandur-go-1.26-modernize

Conversation

@brandur

@brandur brandur commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Follows up #1356 to bring back in some modernizers that I'd disabled to
not make the diff for that original PR gigantic.

In particular:

  • errorsastype: Requires the use of the new errors.AsType helper.
    This is a really nice one and turns this old code:

      var pgErr *pgconn.PgError
      if errors.As(err, &pgErr) {
    

    Into this much nicer generics variant:

      if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
    
  • newexpr: Converts pointer helpers like ptrutil.Ptr(...) to new.
    I remove all uses of ptrutil.Ptr(...), but left its definition in
    rivershared for now because I think it'll allow a little more
    flexibility in what version of River a River Pro installation can use.
    For example, an older version of River Pro could potentially point to
    a newer version of River and still have compilation work (it has
    however been marked as deprecated). I doubt too many people are in
    this situation though so we can probably remove it soon.

  • stditerators: Replaces some manual iteration patterns with newer
    standard library iterator APIs. For example this:

      for i := range typ.NumField() {
          field := typ.Field(i)
    

    Goes to this:

      for field := range typ.Fields() {�[27;5;106~
    

Follows up #1356 to bring back in some modernizers that I'd disabled to
not make the diff for that original PR gigantic.

In particular:

* `errorsastype`: Requires the use of the new `errors.AsType` helper.
  This is a really nice one and turns this old code:

        var pgErr *pgconn.PgError
        if errors.As(err, &pgErr) {

    Into this much nicer generics variant:

        if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {

* `newexpr`: Converts pointer helpers like `ptrutil.Ptr(...)` to `new`.
  I remove all uses of `ptrutil.Ptr(...)`, but left its definition in
  `rivershared` for now because I think it'll allow a little more
  flexibility in what version of River a River Pro installation can use.
  For example, an older version of River Pro could potentially point to
  a newer version of River and still have compilation work (it has
  however been marked as deprecated). I doubt too many people are in
  this situation though so we can probably remove it soon.

* `stditerators`: Replaces some manual iteration patterns with newer
  standard library iterator APIs. For example this:

        for i := range typ.NumField() {
            field := typ.Field(i)

    Goes to this:

        for field := range typ.Fields() {�[27;5;106~
@brandur
brandur requested a review from bgentry August 22, 2026 00:05
@brandur

brandur commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

thx!

@brandur
brandur merged commit f748a5c into master Aug 22, 2026
15 checks passed
@brandur
brandur deleted the brandur-go-1.26-modernize branch August 22, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants