mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-22 19:56:39 +00:00
fc3741365c
* Add Swagger spec test script * Fix Swagger spec errors not related to statuses with polls * Add API tests that post a status with a poll * Fix creating a status with a poll from form params * Fix Swagger spec errors related to statuses with polls (this is the last error) * Fix Swagger spec warnings not related to unused definitions * Suppress a duplicate list update params definition that was somehow causing wrong param names * Add Swagger test to CI - updates Drone config - vendorizes go-swagger - fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version * Put `Sample: ` on its own line everywhere * Remove unused id param from emojiCategoriesGet * Add 5 more pairs of profile fields to account update API Swagger * Remove Swagger prefix from dummy fields It makes the generated code look weird * Manually annotate params for statusCreate operation * Fix all remaining Swagger spec warnings - Change some models into operation parameters - Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields) * Documented that creating a status with scheduled_at isn't implemented yet * sign drone.yml * Fix filter API Swagger errors * fixup! Fix filter API Swagger errors --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package text
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
// Indent inserts prefix at the beginning of each non-empty line of s. The
|
|
// end-of-line marker is NL.
|
|
func Indent(s, prefix string) string {
|
|
return string(IndentBytes([]byte(s), []byte(prefix)))
|
|
}
|
|
|
|
// IndentBytes inserts prefix at the beginning of each non-empty line of b.
|
|
// The end-of-line marker is NL.
|
|
func IndentBytes(b, prefix []byte) []byte {
|
|
var res []byte
|
|
bol := true
|
|
for _, c := range b {
|
|
if bol && c != '\n' {
|
|
res = append(res, prefix...)
|
|
}
|
|
res = append(res, c)
|
|
bol = c == '\n'
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Writer indents each line of its input.
|
|
type indentWriter struct {
|
|
w io.Writer
|
|
bol bool
|
|
pre [][]byte
|
|
sel int
|
|
off int
|
|
}
|
|
|
|
// NewIndentWriter makes a new write filter that indents the input
|
|
// lines. Each line is prefixed in order with the corresponding
|
|
// element of pre. If there are more lines than elements, the last
|
|
// element of pre is repeated for each subsequent line.
|
|
func NewIndentWriter(w io.Writer, pre ...[]byte) io.Writer {
|
|
return &indentWriter{
|
|
w: w,
|
|
pre: pre,
|
|
bol: true,
|
|
}
|
|
}
|
|
|
|
// The only errors returned are from the underlying indentWriter.
|
|
func (w *indentWriter) Write(p []byte) (n int, err error) {
|
|
for _, c := range p {
|
|
if w.bol {
|
|
var i int
|
|
i, err = w.w.Write(w.pre[w.sel][w.off:])
|
|
w.off += i
|
|
if err != nil {
|
|
return n, err
|
|
}
|
|
}
|
|
_, err = w.w.Write([]byte{c})
|
|
if err != nil {
|
|
return n, err
|
|
}
|
|
n++
|
|
w.bol = c == '\n'
|
|
if w.bol {
|
|
w.off = 0
|
|
if w.sel < len(w.pre)-1 {
|
|
w.sel++
|
|
}
|
|
}
|
|
}
|
|
return n, nil
|
|
}
|