added in License
This commit is contained in:
parent
9d40c9d7ec
commit
a2739dbbcd
27
LICENSE
Normal file
27
LICENSE
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2024 Patial Tech. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Patial Tech. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1,3 +1,6 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
@ -31,7 +35,7 @@ func Request() func(http.Handler) http.Handler {
|
||||
// ID
|
||||
requestID := r.Header.Get("X-Request-Id")
|
||||
if requestID == "" {
|
||||
requestID = uid.ULID()
|
||||
requestID = uid.NewUUID()
|
||||
}
|
||||
ctx = context.WithValue(ctx, RequestIDKey, requestID)
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
//
|
||||
// copied from https://github.com/joho/godotenv/blob/main/parser.go
|
||||
// ported from https://github.com/joho/godotenv/blob/main/parser.go
|
||||
//
|
||||
|
||||
const (
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
//
|
||||
// copied from https://github.com/joho/godotenv/blob/main/godotenv.go
|
||||
// ported from https://github.com/joho/godotenv/blob/main/godotenv.go
|
||||
//
|
||||
|
||||
// Read all env (with same file loading semantics as Load) but return values as
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
//
|
||||
// copied from https://github.com/joho/godotenv/blob/main/godotenv.go
|
||||
// ported from https://github.com/joho/godotenv/blob/main/godotenv.go
|
||||
//
|
||||
|
||||
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
|
66
db/client.go
66
db/client.go
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
@ -54,48 +58,52 @@ func Client() *ent.Client {
|
||||
return cl
|
||||
}
|
||||
|
||||
type entity interface {
|
||||
GetID() (int64, error)
|
||||
}
|
||||
|
||||
// A AuditHook is an example for audit-log hook.
|
||||
func AuditHook(next ent.Mutator) ent.Mutator {
|
||||
type Entity interface {
|
||||
GetID() (int64, error)
|
||||
}
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (v ent.Value, err error) {
|
||||
var id int64
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
saveAudit(ctx, id, m.Type(), m.Op().String(), time.Since(start), err)
|
||||
saveAudit(ctx, m.Type(), m.Op(), v, err, time.Since(start))
|
||||
}()
|
||||
|
||||
v, err = next.Mutate(ctx, m)
|
||||
|
||||
if en, ok := v.(Entity); ok {
|
||||
id, _ = en.GetID()
|
||||
}
|
||||
logger.Info("** %v", v)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func saveAudit(_ context.Context, entID int64, entT, op string, d time.Duration, err error) {
|
||||
logger.Info("audit: %d, %s, %s, %s, %v", entID, entT, op, d, err)
|
||||
// ml.SetCreatedAt(time.Now())
|
||||
// if usr := auth.CtxUser(ctx); usr != nil {
|
||||
// ml.SetByID(usr.ID)
|
||||
// ml.SetBy(usr.DisplayName)
|
||||
// }
|
||||
func saveAudit(ctx context.Context, t string, op ent.Op, v ent.Value, err error, d time.Duration) {
|
||||
if t == "Audit" {
|
||||
// skip Audit table operations
|
||||
return
|
||||
}
|
||||
|
||||
// switch op := m.Op(); {
|
||||
// case op.Is(ent.OpCreate):
|
||||
// ml.SetOperation("Create")
|
||||
var entOp string
|
||||
switch {
|
||||
case op.Is(ent.OpCreate):
|
||||
entOp = "Create"
|
||||
case op.Is(ent.OpDelete):
|
||||
entOp = "Delete"
|
||||
case op.Is(ent.OpDeleteOne):
|
||||
entOp = "DeleteOne"
|
||||
case op.Is(ent.OpUpdate):
|
||||
entOp = "Update"
|
||||
case op.Is(ent.OpUpdateOne):
|
||||
entOp = "UpdateOne"
|
||||
}
|
||||
|
||||
// case op.Is(ent.OpUpdate):
|
||||
// ml.SetOperation("Update")
|
||||
// case op.Is(ent.OpUpdateOne):
|
||||
// ml.SetOperation("UpdateOne")
|
||||
big.
|
||||
reqID := ctx.Value("RequestID")
|
||||
ip := ctx.Value("RequestIP")
|
||||
ua := ctx.Value("RequestUA")
|
||||
|
||||
// case op.Is(ent.OpDelete):
|
||||
// ml.SetOperation("Delete")
|
||||
// case op.Is(ent.OpDeleteOne):
|
||||
// ml.SetOperation("DeleteOne")
|
||||
// }
|
||||
if en, ok := v.(entity); ok {
|
||||
id, _ := en.GetID()
|
||||
logger.Info("%s %s %s-%s(%d) ip=%s ua=%s t=%v error=%e", reqID, status, op.String(), t, id, ip, ua, d, err)
|
||||
} else {
|
||||
logger.Info("%s %s %s-%s ip=%s ua=%s t=%v error=%e", reqID, status, op.String(), t, ip, ua, d, err)
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mailer
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package message
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package message
|
||||
|
||||
import _ "embed"
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mailer
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
// EmailResetPWD link to user to reset password
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package crypto
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package crypto
|
||||
|
||||
import "testing"
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package logger
|
||||
|
||||
import (
|
||||
|
@ -1,5 +1,9 @@
|
||||
//go:build darwin
|
||||
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package open
|
||||
|
||||
import (
|
||||
|
@ -1,5 +1,9 @@
|
||||
//go:build linux
|
||||
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package open
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package open
|
||||
|
||||
// WithDefaultApp open a file, directory, or URI using the OS's default application for that object type.
|
||||
|
@ -1,5 +1,9 @@
|
||||
//go:build windows
|
||||
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package open
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package structs
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package uid
|
||||
|
||||
import "github.com/sqids/sqids-go"
|
||||
|
23
util/uid/uuid.go
Normal file
23
util/uid/uuid.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package uid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gitserver.in/patialtech/rano/util/logger"
|
||||
)
|
||||
|
||||
func NewUUID() string {
|
||||
id, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
logger.Incident(context.Background(), "New UUID", err.Error())
|
||||
return fmt.Sprintf("%d", time.Now().UTC().UnixNano())
|
||||
}
|
||||
return id.String()
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validate
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
import { gql } from '@urql/svelte';
|
||||
export const Me = gql`
|
||||
query Me {
|
||||
|
@ -1,8 +1,12 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
import { Client, cacheExchange, fetchExchange } from '@urql/svelte';
|
||||
|
||||
export function newClient(url: string) {
|
||||
return new Client({
|
||||
url,
|
||||
exchanges: [ fetchExchange]
|
||||
exchanges: [fetchExchange]
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
@ -1 +1,5 @@
|
||||
// Copyright 2024 Patial Tech. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
export let authUser = $state();
|
||||
|
@ -1,12 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { type Snippet } from "svelte";
|
||||
import { type Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
children: Snippet
|
||||
children: Snippet;
|
||||
}
|
||||
const { children }:Props = $props();
|
||||
const { children }: Props = $props();
|
||||
</script>
|
||||
|
||||
// Copyright 2024 Patial Tech. All rights reserved. // Use of this source code is governed by a BSD-style // license
|
||||
that can be found in the LICENSE file.
|
||||
|
||||
<button>
|
||||
{@render children()}
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user