mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-02-04 04:29:43 +01:00
use bufio scanner
This commit is contained in:
parent
28193df3d0
commit
6ea156cc7d
@ -18,6 +18,7 @@
|
|||||||
package subscriptions
|
package subscriptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -687,21 +688,25 @@ func permsFromPlain(
|
|||||||
permType gtsmodel.DomainPermissionType,
|
permType gtsmodel.DomainPermissionType,
|
||||||
body io.ReadCloser,
|
body io.ReadCloser,
|
||||||
) ([]gtsmodel.DomainPermission, error) {
|
) ([]gtsmodel.DomainPermission, error) {
|
||||||
// Read body into memory as bytes.
|
// Scan + split by line.
|
||||||
b, err := io.ReadAll(body)
|
sc := bufio.NewScanner(body)
|
||||||
|
|
||||||
|
// Read into domains
|
||||||
|
// line by line.
|
||||||
|
var domains []string
|
||||||
|
for sc.Scan() {
|
||||||
|
domains = append(domains, sc.Text())
|
||||||
|
}
|
||||||
|
|
||||||
// Whatever happened, we're
|
// Whatever happened, we're
|
||||||
// done with the body now.
|
// done with the body now.
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
// Check if error reading body.
|
// Check if error reading body.
|
||||||
if err != nil {
|
if err := sc.Err(); err != nil {
|
||||||
return nil, gtserror.NewfAt(3, "error decoding into plain: %w", err)
|
return nil, gtserror.NewfAt(3, "error decoding into plain: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coerce to newline-separated list of domains.
|
|
||||||
domains := strings.Split(string(b), "\n")
|
|
||||||
|
|
||||||
// Convert raw domains to permissions.
|
// Convert raw domains to permissions.
|
||||||
perms := make([]gtsmodel.DomainPermission, 0, len(domains))
|
perms := make([]gtsmodel.DomainPermission, 0, len(domains))
|
||||||
for _, domainRaw := range domains {
|
for _, domainRaw := range domains {
|
||||||
|
Loading…
Reference in New Issue
Block a user