chore(refactor): partial port of Add API for Variables (#29520)

The commit has, in addition to the implementation of the API, a few
function refactor that are useful in backports.

---

close #27801

---------

Co-authored-by: silverwind <me@silverwind.io>
(cherry picked from commit 62b073e6f31645e446c7e8d6b5a506f61b47924e)

Conflicts:
	- modules/util/util.go
          Trivial resolution, only picking the newly introduced function
	- routers/api/v1/swagger/options.go
          Trivial resolution. We don't have UserBadges, don't pick that part.
	- templates/swagger/v1_json.tmpl
          Regenerated.
(cherry picked from commit 16696a42f5)
This commit is contained in:
sillyguodong 2024-03-29 04:40:35 +08:00 committed by Earl Warren
commit 0e82cf121d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 139 additions and 73 deletions

View file

@ -236,3 +236,8 @@ func TestToPointer(t *testing.T) {
val123 := 123
assert.NotSame(t, &val123, ToPointer(val123))
}
func TestReserveLineBreakForTextarea(t *testing.T) {
assert.Equal(t, "test\ndata", ReserveLineBreakForTextarea("test\r\ndata"))
assert.Equal(t, "test\ndata\n", ReserveLineBreakForTextarea("test\r\ndata\r\n"))
}